Computer Science, asked by Tajinder2211, 9 months ago

Write a menu driven program to generate the following series 1 4 3 16 5 36....n

Answers

Answered by anindyaadhikari13
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 kothambra
0

Answer:

..,.,.,.,.,..,.,,..,.,..,..,.,..,.,.,

Similar questions