Computer Science, asked by kh5u9shaminiraudhan, 1 year ago

Write the Program for the Given Output
Write a program to print the following series: 2 22 222 2222 22222 222222

Answers

Answered by MohamedAzil
2

Answer:

n=int(input("no.of terms"))

s=int(input("enter number"))

start=s

sum=0

for i in range(0,n):

   print(start,end=" ")

   sum+=start

   start=(start*10)+s

Explanation:

Answered by qwstoke
0

Here is the required code in C++ for the given series:

CODE:

#include <iostream>

using namespace std;

int main() {

   int num = 2;

   for(int i=1; i<=6; i++) {

       for(int j=1; j<=i; j++) {

           cout << num;

       }

       cout << " ";

   num = (num*10) + 2;

   }

   return 0;

}

In this program, we have used nested for loops to print the series. The outer loop runs for 6 iterations, and the inner loop prints the number '2' the required number of times based on the current iteration number. The value of the 'num' variable is updated in each iteration to generate the next number in the series. Finally, we use the 'cout' statement to print the space between each number in the series.

#SPJ2

Similar questions