mountain-shape of stars

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.
Last edited on
it's really easy.... you should look up for loops. This can easily be done in a single line of code:

for(unsigned int 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.
This is what I have so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include <iostream>
using namespace 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;
}
}
You'd probably have a much easier time of it if you were to write your own code instead of messing with stuff someone else gave you.

Also, pick a language: C or C++.
Topic archived. No new replies allowed.