Use for loops to construct a program that displays a pyramid of Xs on the screen. The pyramid should look like: X X X X X X X X X X X X X X X
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i, j, k, c=5;
for(i=1;i<=5;i++)
{
for(k=1;k<c;k++)
{
cout<<" ";
}
for(j=1;j<=(2*i)-1;j++)
{
cout<<"X";
}
cout<<endl;
c--;
}
system("pause");
return 0;
}
Comments
Leave a comment