Write a menu driven program to generate the following series 1 4 3 16 5 36....n
Answers
Answered by
23
Here is your answer. It's quite easy.
First of all, we have to know the logic of the program.
We can see that all the even term of the series is a perfect square.
That is, the series would be like.
1 2² 3 4² 5 6²......... n
So, to print the series, follow the given code,
import java.util.*;
class Program
{
static void main()
{
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++)
{
if(i%2!=0)
System.out.print(i+" ");
else
System.out.print(i*i+ " ");
}
}
}
Answered by
0
Answer:
..,.,.,.,.,..,.,,..,.,..,..,.,..,.,.,
Similar questions
Hindi,
4 months ago
English,
4 months ago
Hindi,
4 months ago
Computer Science,
1 year ago
Math,
1 year ago