How to write a program that print out a mountain-shape of stars. For example, if use input a 10, you
will print out 10-line of stars, 1 in the first line, 2 in the second line, ..., 10 in the tenth line with a
shape like a mountain with star 1 sitting at the middle and top.
it's really easy.... you should look up for loops. This can easily be done in a single line of code:
for(unsignedint x = 1; x < 11; x++) cout<< std::string(x, '*')<< '\n';
If you're taking a class, I highly advise you figure out what the code means (and how to use it) or you will fail utterly, and I won't help you: I'll just laugh at you.
#include<iostream>
#include <iostream>
usingnamespace std;
int main()
{
int n, c, k, space, count = 1;
printf("Enter number of rows\n");
scanf("%d",&n);
space = n;
for ( c = 1 ; c <= n ; c++)
{
for( k = 1 ; k < space ; k++)
printf(" ");
for ( k = 1 ; k <= c ; k++)
{
printf("*");
if ( c > 1 && count < c)
{
printf(" ");
count++;
}
}
printf("\n");
space--;
count = 1;
}
return 0;
}
}