Computer Science, asked by ShovanBiswas, 1 year ago


WAP to print the n terms of the series 1,4,9,61,52,63,94,...... n terms.

plz write in java and write a step-by-step procedure of doing it.

thanks you,​

Attachments:

Answers

Answered by avinashmurmu99311
7

class series

{

public static void main (String args[])

{

int n= 10,i,d,rev=0,s,a=1;

( for i=1;i<=10;i++)

{

s=a*a;

if(i<10)

System.out.print(s);

else

{

while(s>0)

{

d=s%10;

s=s/10;

rev=rev*10+d;

}

S.o.p(rev);

}

}

}

Answered by tiger009
1

Print following series

Output:

Enter the number: 8

1, 4, 9, 61, 52, 63, 94, 46

Explanation:

The following are the program in the C++ Programming Language.

//set header file

#include <iostream>

//define namespace

using namespace std;

//define main method

int main() {

 //declare integer type variables

 int n,rem ;

 //print the message

 cout<<"Enter the number: ";

 //get input in the variable from the user

 cin>>n;

 //set the for loop  

 for(int i=1;i<=n;i++)

 { //declare integer type variable to 0

   int rev=0;

   //declare variable that stores the square of each number

   int x=i*i;

   //print the variable if x is less than 10

   if(x<10)

   {

     cout<<x<<", ";

   }

   //otherwise

   else

   { //reverse the number that is greater than 10

     while(x>0)

     {

       rem=x%10;

       rev=(rev*10)+rem;

       x=x/10;

     }

     //and print the reversed variable

     cout<<rev<<", ";

   }

 }

}

The following are the description of the program.

  • Firstly, set the required header file and define namespaces and the main method.
  • Then, declare two integer data type variables which are 'n' and 'rem'.
  • Then, print the message and get input in the variable 'n' from the user.
  • Set the for loop that iterates from 1 and ends at the user input then, declares a variable 'rev' and initializes it to 0 and declare a variable 'x' that stores the square from 1 to the variable 'n'.
  • Set the if-else conditional statement, that prints the variable 'x' if the variable 'x' is less than 0 otherwise it reverse the number and print that reversed number.

Learn More:

https://brainly.in/question/1511868

Similar questions