Thread: Nested loop frustration

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    Nested loop frustration

    Hi guys, I'm having trouble with the following code: first problem is, i'm really not very good at mathematics and the equation to represent the spaces eludes me.
    What am i doing wrong please. I've visited this link where salem was helping another individual and it clarified a few things in terms of the structure but i'm still a little mystified at the output i get. Compile it and you see the weird structure.
    thank you.

    Code:
    /* pyramid.c output:  *
                         ***
                        *****
                       *******
                      *********
    
    */
    
    
    
    #include <stdio.h>
    int main(void){
    
    int r,c,s, ht=5;
    
    for (r = 1; r <=ht; r++){ //number of rows
       for (s = 1; s <=(ht-(r/2)); s++) // determine spaces
          printf(" ");
    
       for (c = 1; c <=r; c++)//determine num of charaters to place
         printf("%c", '*');
    
    printf("\n");
    }
    getchar();
    return 0;
    }
    Last edited by caroundw5h; 03-13-2004 at 12:12 PM.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 01:34 PM
  3. output from nested while loop
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-22-2002, 09:30 AM
  4. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM
  5. Need help with simple programs...
    By BCole19 in forum C++ Programming
    Replies: 22
    Last Post: 08-30-2001, 09:45 PM