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..
#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;
}
Comments
Leave a comment