0

Hi, I have a homework assignment that is giving me some problems. I need to make a pyramid of * with a spaces and n rows long. It should look something like this:
____*
___* *
__* * *
_* * * *
* * * * *
I have most of it but my compiler is still coming up with errors. Please help.

# include <stdio.h>
#include <stdlib.h>
int main (void)
{
    int n;
    for (int i=0; i<n; i++);
    {
        for (int j=0; j<n-1-i; j++);
            printf (" ");
    }
    {  
        for (int k=0; k<(2*(i+1));k++)
            printf ("* ");
    }
    printf ("\n");
 
    system ("PAUSE"); 
    return 0;
}
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by WolfPack
0
#include <stdio.h> // There should be no spaces between # and include
#include <stdlib.h>
int main (void)
{
    int n = 9; // initialize n to the value you want
    for (int i=0; i<n; i++) // deleted the semicolon
    {
        // You print spaces until n - 1 - i
        for (int j=0; j<n-1-i; j++) // deleted the semicolon
            printf (" ");
        // After printing spaces print * until n
        for (int k=n-1-i; k<n;k++)
            printf ("* ");
        printf ("\n");
    }
 
    system ("PAUSE"); // use cin.get() or something
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.