Program to print series 2,15,41,80...n

Problem statement:- Program to print series 2,15,41,80...n

 Data requirement:-

   Input Data:- n

  Output Data:-value

  Additional Data:-i

Program in C
  
Here is the source code of the C Program to print series 2,15,41,80...n.

Code:

#include<stdio.h>
int main()
{
    int n,i,value=2;
    printf("Enter the range of number:");
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
     printf("%d ",value);
     value+=i*13;
    }
}

Input/Output:
Enter the range of number:5
2 15 41 80 132

Program in C++
  
Here is the source code of the C++ Program to print series 2,15,41,80...n.

Code:

#include<iostream>
using namespace std;
int main()
{
    int n,i,value=2;
    cout<<"Enter the range of number:";
    cin>>n;
    for(i=1;i<=n;i++)
    {
     cout<<value<<" ";
      value+=i*13;
    }
}

Input/Output:
Enter the range of number:7
2 15 41 80 132 197 275

Program in Java
  
Here is the source code of the Java Program to print series 2,15,41,80...n.

Code:

import java.util.Scanner;
public class p22 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
    int n,i,value=2;
    System.out.println("Enter the range of number:");
    n=cs.nextInt();
    for(i=1;i<=n;i++){
    System.out.print(value+" ");
        value+=i*13;
    }
    cs.close();
}
}

Input/Output:
Enter the range of number:
9
2 15 41 80 132 197 275 366 470 

Program in Python
  
Here is the source code of the Python Program to print series 2,15,41,80...n.

Code:

print("Enter the range of number(Limit):")
n=int(input())
i=1
value=2
while(i<=n):
    print(value,end=" ")
    value+=i*13
    i+=1

Input/Output:
Enter the range of number(Limit):
22
2 15 41 80 132 197 275 366 470 587 717 860 1016 1185 1367 1562 1770 1991 2225 2472 2732 3005 

Post a Comment

0 Comments