Problem statement:- Program to print series 6,9,14,21,30,41,54...N
Data requirement:-
Input Data:- n
Output Data:-value
Additional Data :- i,j
Program in C
Here is the source code of the C Program to print series 6,9,14,21,30,41,54...N
Code:
#include<stdio.h>
int main()
{
int n,i,j=3,value=6;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d ",value);
value+=j;
j+=2;
}
}
int main()
{
int n,i,j=3,value=6;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d ",value);
value+=j;
j+=2;
}
}
Input/Output:
Enter the range of number:8
6 9 14 21 30 41 54 69
Program in C++
6 9 14 21 30 41 54 69
Program in C++
Here is the source code of the C++ Program to print series 6,9,14,21,30,41,54...N
Code:
#include<iostream>
using namespace std;
int main()
{
int n,sum=0,i,j=3,value=6;
cout<<"Enter the range of number:";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<value<<" ";
value+=j;
j+=2;
}
}
Input/Output:
Enter the range of number:11
6 9 14 21 30 41 54 69 86 105 126
Program in Java
6 9 14 21 30 41 54 69 86 105 126
Program in Java
Here is the source code of the Java Program to print series 6,9,14,21,30,41,54...N
Code:
import java.util.Scanner;
public class p32 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,j=3,value=6;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++)
{
System.out.print(value+" ");
value+=j;
j+=2;
}
cs.close();
}
}
public class p32 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,j=3,value=6;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++)
{
System.out.print(value+" ");
value+=j;
j+=2;
}
cs.close();
}
}
Input/Output:
Enter the range of number:
15
6 9 14 21 30 41 54 69 86 105 126 149 174 201 230
Program in Python
Here is the source code of the Python Program to print series 6,9,14,21,30,41,54...N
Code:
print("Enter the range of number(Limit):")
n=int(input())
i=1
j=3
value=6
while(i<=n):
print(value,end=" ")
value+=j
j+=2
i+=1
n=int(input())
i=1
j=3
value=6
while(i<=n):
print(value,end=" ")
value+=j
j+=2
i+=1
Input/Output:
Enter the range of number(Limit):
5
6 9 14 21 30
5
6 9 14 21 30
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box