Answer to Question #278503 in C++ for aribah

Question #278503

Write a program that asks the user for positive integer number less than 30. The program should then display a pattern on the screen using the character "*". The number entered by the user will be out input. So if user enters 20, it will display:

the program will use nested for loop..


1
Expert's answer
2021-12-11T05:52:14-0500
#include <iostream>
using namespace std;
int main()
{
   int r, i, j, s;
   cout << "How many rows? : ";
   cin >> r;
   if(r<30)
   {
   	  for(i = 1; i <= r; i++)
   {
      for(s = i; s < r; s++)
      {
         cout << " ";
      }
      for(j = 1; j <= (2 * i - 1); j++)
      {
         cout << "*";
      }
      cout << "\n";
   }
   }
   else{
   	cout<<"Enter an integer less than 30";
   }
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog