-
C (
http://www.daniweb.com/forums/forum118.html)
| morning_star_18 | Oct 17th, 2006 2:12 am | |
| Hi, would you mind helping me with my homework? 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;
} |
| WolfPack | Oct 17th, 2006 3:19 am | |
| Re: Hi, would you mind helping me with my homework? #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;
} |
| All times are GMT -4. The time now is 4:40 am. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC