Program to print series 6,11,21,36,56...n

Problem statement:- Program to print series 6,11,21,36,56...n.

 Data requirement:-

   Input Data:- n

  Output Data:-pr

  Additional Data:- i, diff.

Program in C
  
Here is the source code of the C Program to print series 6,11,21,36,56...n.

Code:

#include<stdio.h>
int main()
{
    int n,i,pr=6,diff=5;
    printf("Enter the range of number(Limit):");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        printf("%d ",pr);
        pr=pr+diff;
        diff=diff+5;
    }
}

Input/Output:
Enter the range of number(Limit):5
6 11 21 36 56

Program in C++

Here is the source code of the C++ Program to print series 6,11,21,36,56...n.

Code:

#include<iostream>
using namespace std;
int main()
{
    int n,i,pr=6,diff=5;
    cout<<"Enter the range of number(Limit):";
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cout<<pr<<" ";
        pr=pr+diff;
        diff=diff+5;
    }
}

Input/Output:
Enter the range of number(Limit):7
6 11 21 36 56 81 111

Program in Java

Here is the source code of the Java Program to print series 6,11,21,36,56...n.

Code:

import java.util.Scanner;
public class Print_Series6 {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,i,pr=6,diff=5;
   System.out.printf("Enter the range of number(Limit):");
    n=sc.nextInt();
    for(i=1;i<=n;i++)
    {
    System.out.print(pr+" ");
    pr=pr+diff;
        diff=diff+5;
    }
    sc.close();
}
}

Input/Output:
Enter the range of number(Limit):8
6 11 21 36 56 81 111 146 

Program in Python

Here is the source code of the Python Program to print series 6,11,21,36,56...n.

Code:

n=int(input("Enter the range of number(Limit):"))
i=1
pr=6
diff=5
while i<=n:
    print(pr,end=" ")
    pr = pr + diff
    diff = diff + 5
    i+=1

Input/Output:
Enter the range of number(Limit):4
6 11 21 36 


Post a Comment

0 Comments