Hi, would you mind helping me with my homework?

Reply

Join Date: Oct 2006
Posts: 1
Reputation: morning_star_18 is an unknown quantity at this point 
Solved Threads: 0
morning_star_18 morning_star_18 is offline Offline
Newbie Poster

Hi, would you mind helping me with my homework?

 
0
  #1
Oct 17th, 2006
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.

  1. # include <stdio.h>
  2. #include <stdlib.h>
  3. int main (void)
  4. {
  5. int n;
  6. for (int i=0; i<n; i++);
  7. {
  8. for (int j=0; j<n-1-i; j++);
  9. printf (" ");
  10. }
  11. {
  12. for (int k=0; k<(2*(i+1));k++)
  13. printf ("* ");
  14. }
  15. printf ("\n");
  16.  
  17. system ("PAUSE");
  18. return 0;
  19. }
Last edited by morning_star_18; Oct 17th, 2006 at 2:14 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Hi, would you mind helping me with my homework?

 
0
  #2
Oct 17th, 2006
#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;
}
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC