Use" for" loops to construct a program that displays a pyramid of numbers on the screen.
The pyramid should look like this:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ask the user to enter a digit(0-9) and display the pyramid with limit up to that number( as shown above).
#include
main()
{
int i,n,j;
cout<<"please enter number: ";
cin>>n;
for ( i = 1; i <= n; i++)
{
for ( j = 0; j < n - i + 2; j++)
cout<<(' ');
for ( j = 0; j < i; j++)
{
cout<<(i);
cout<<(' ');
}
cout<<"\n";
}
}
2006-10-27
02:09:10
·
2 answers
·
asked by
Muhammad A
1
in
Computers & Internet
➔ Programming & Design