Print the series: 2, 12, 36, 80, 150, 1100 ....... n no. of terms
Answers
Answered by
3
Question:-
Write a program to print the series.
2 12 36 80 150 1100
Logic:-
2 = 1² + 1³
12 = 2² + 2³
36 = 3² + 3³
80 = 4² + 4³
and this will continue.
Now, we will write the program for the following series.
Program:-
In Java
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of terms for the series: ");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
int a=i*i + i*i*i;
System.out.print(a+" ");
}
}
}
In Python
n=int(input("Enter the number of terms for the series: ");
for i in range (0,n):
a=i*i + i*i*i
print(a, end=" ")
Similar questions