Do I need another loop?

This is a discussion on Do I need another loop? within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to write a program that will change the following triangle: * * ** ** *** *** ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    1

    Unhappy Do I need another loop?

    Hi, I am trying to write a program that will change the following triangle:
    * *
    ** **
    *** ***
    **** ****
    ***** into *****
    ****** ******
    ******* *******
    ******** ********
    ********* *********
    ********** **********

    using a single printf("*"); a single printf(""); and a single printf("\n");

    Would I need another loop to get the spaces in front of the asterisks or would I just need to modify the expressions in the for loop? Thanks for your help!

  2. #2
    Registered User Natase's Avatar
    Join Date
    Aug 2001
    Posts
    123
    Damn that's hard to read... may have to post this question again methinks...

  3. #3
    Registered User Natase's Avatar
    Join Date
    Aug 2001
    Posts
    123
    There might be an easier way but this meets your requirements

    Code:
    int i,j;
    for (i=10;i>0;i--) {
       for (j=0;j<i;j++) {
          printf(" ");
       }
       for (j=10;j>i;j--) {
          printf("*");
       }
       printf("\n");
    }
    here's hoping I've got the hang of posting properly formatted code...

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. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21