Computer Science, asked by itzmewiki, 9 months ago

Write a program to generate the first 'n' terms of the following series 121, 225, 361,...

Answers

Answered by bipinvjohn
19

Answer:

#include<iostream>

int main ()

{

   int n, a=11, x=4, i=0, num;

   std::cin>>n;

   

for(i=0;i<n;i++)

{

   num=a*a;

   std::cout<<num<<" ";

   a=a+4;

}

}

Answered by vishakasaxenasl
0

Answer:

The following Python code will solve the above problem. Just copy and paste the code into any python IDE:

n = int(input())

start = 11

  while(n!=0):

   print(start**2, end=",")

   start +=2

   n-=1

Explanation:

  • First, we take the n terms as input from the user.
  • we create a start variable with a value of 11.
  • The logic of the series is to print the square of odd numbers starting from 11.
  • Like square of 11 = 121
  • square of 15 = 225
  • square of 19 = 191
  • Then we start a loop to iterate n number of times.
  • ** operator will calculate the square for us without using any math library function.
  • the start is incremented by 2 to reach the next odd number
  • n is decremented by 1 so that we move to the termination condition of the loop.

#SPJ2

Similar questions