I am trying to output a number of lines, given by the user, of stars shaped as a triangle below:
*********
*******
*****
***
*
i have got the following code:
void line (int n, char c)
{
for (int i = 1;i <= n; i++)
{
for (int m = 0 ;m <= n-i; m++)
for (int s=0; s <= m; s++)
cout << c ;
cout << endl;
}
}
int main()
{
int n = 0;
cout << "Enter number of lines: ";
cin >> n;
line (n,'*');
}
but it print out the stars in the following format:
*********
*******
*****
***
*
Any help will be appreciated. Thank you :)