Problem statement:- Program to print series 0 2 6 12 20 30 42 ...N.
Data requirement:-
Input Data:- n
Output Data:-i
Additional Data:- Nothing.
Program in C
Input Data:- n
Output Data:-i
Additional Data:- Nothing.
Program in C
Here is the source code of the C Program to print series 0 2 6 12 20 30 42 ...N.
Code:
#include<stdio.h>
int main()
{
int n,i;
printf("Enter the range of number(Limit):");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d ",(i*i)-i);
}
}
Enter the range of number(Limit):7
0 2 6 12 20 30 42
Program in C++
Here is the source code of the C++ Program to print series 0 2 6 12 20 30 42 ...N.
Code:
#include<iostream>
using namespace std;
int main()
{
int n,i;
cout<<"Enter the range of number(Limit):";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<(i*i)-i<<" ";
}
}
Input/Output:
Enter the range of number(Limit):5
0 2 6 12 20
Program in Java
Here is the source code of the Java Program to print series 0 2 6 12 20 30 42 ...N.
Code:
import java.util.Scanner;
public class Print_Series11 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,i;
System.out.printf("Enter the range of number(Limit):");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
System.out.print((i*i)-i+" ");
}
sc.close();
}
}
Enter the range of number(Limit):6
0 2 6 12 20 30
Program in Python
Here is the source code of the Python Program to print series 0 2 6 12 20 30 42 ...N.
Code:
n=int(input("Enter the range of number(Limit):"))
i=1
while i<=n:
print((i*i)-i,end=" ")
i+=1
Enter the range of number(Limit):7
0 2 6 12 20 30 42
Most Recommend Questions:-
More Questions:-
1 Comments
Ok but in python it's wrong
ReplyDeletePlease do not Enter any spam link in the comment box