Computer Science, asked by megreat, 1 month ago

Write a program that will output the following using Nested loops. 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1​

Answers

Answered by omyogeshpatel
0

for i in range(2, 10, 2) :

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) :

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ')

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ') print()

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ') print()OUTPUT

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ') print()OUTPUT2

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ') print()OUTPUT2 4 4

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ') print()OUTPUT2 4 4 6 6 6

for i in range(2, 10, 2) : for j in range(2, i + 1, 2) : print(i, end = ' ') print()OUTPUT2 4 4 6 6 68 8 8 8

MAKE ME BRILLIANT ANS

Answered by rachel002
0

Answer:

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

   int i,j,rows; //variable declaration

   cout<<"Enter the number of rows: ";

   cin>>rows; //Take input the number of rows from user

   cout<<"\n";

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

   {

       for(j=i; j>=1; j--)

   {

         cout<<j; //Display pattern

   }

   cout<<"\n"; //move to next line

   }

   getch();

   return 0;

}

Explanation:

This is a C++ program for reverse numbers but in a pyramid form

Here you can enter how many rows you want

Since you have asked for 5 , you can enter 5 for number of rows

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

   int i,j,rows; //variable declaration

   cout<<"Enter the number of rows: ";

   cin>>rows; //Take input the number of rows from user

   cout<<"\n";

   for(i=1; i<=rows; i++){

       for(j=i; j>=1; j--){

         cout<<j; //Display pattern

   }

   cout<<"\n";//move to next line

   }

   getch();

   return 0;

}

If you want all the numbers to appear in a row like how you have asked, you can remove the line I have underlined to make it appear in a row.

Hope this helps

Similar questions