Thread: Program not quite doing what I want it to do.

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    13

    Program not quite doing what I want it to do.

    I need my program to print this out:

    *****
    ****
    ***
    **
    *

    Thing is is that it only prints out this and nothing else:

    *****

    Here's my code:

    Code:
    #include <stdio.h>
    
    main(){
    
    
        int i, j;
    
    
        i=1;
        j=5;
    
    
        while(i<=5){
            while(j>=i){
            printf("*");
            i++;
        }
        printf("\n");
        j--;
        }
    
    
        return 0;
    }
    Any help is greatly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Perhaps if you named the variables 'numLines' and 'numStars', the code would make more sense.

    Being consistent over indentation would be a help as well.

    And main should explicitly return an int as in
    int main ( )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-15-2016, 03:29 PM
  2. Replies: 2
    Last Post: 09-09-2014, 02:36 PM
  3. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  4. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM

Tags for this Thread