Write a C++ program that asks the user to enter a number N .After that, print N lines using asterisk (*) in a
triangle shape as shown below;
Sample Input:
Enter number of lines to print: 6
#include<iostream>
using namespace std;
int main()
{
int i, space, rowSize, k=0;
cout<<"Enter number of lines to print: ";
cin>>rowSize;
for(i=1; i<=rowSize; i++)
{
for(space=1; space<=(rowSize-i); space++)
cout<<" ";
while(k!=(2*i-1))
{
cout<<"* ";
k++;
}
k=0;
cout<<endl;
}
cout<<endl;
cin>>rowSize;
return 0;
}
Comments
Leave a comment