944,218 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1331
  • C RSS
Oct 17th, 2006
0

Hi, would you mind helping me with my homework?

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
morning_star_18 is offline Offline
1 posts
since Oct 2006
Oct 17th, 2006
0

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;
}
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Other loop than 'for'?
Next Thread in C Forum Timeline: Console Programming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC