Thread: Hi everyone, please help me! :(

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    14

    Hi everyone, please help me! :(

    Greetings everyone,

    First off, I'd like to thank the administration of this forum, for keeping this forum one of the best learning resources for C and C++ programming... I'm new to C and I was suprised by the numerous useful and informative posts that you members have been posting since long.... I searched for other C programming forums too, but didn't come up with anyone that can be said better than this one!

    Anyway, let me get to the point... I need you to do me a little favour, which I'll be more than happy to return.

    I need to write a program in C that uses either FOR or WHILE condition to print the following diaplay on the screen:

    *
    * *
    * * *
    * * * *

    I did something similar some days back, but i really can't figure out how to make this one... Hope you can be of some help to me here...

    Thanks for any replies....

  2. #2
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134
    Ok ummm do a search there are many answers to this one
    And To All Those Opposed, WELL !!!
    >Deleted< " Looks like a serial no."

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    14
    Hi,

    Thanks a lot for your prompt reply... I did some searches, but didn't find anything related to this... I'm sure that my search keywords aren't good... Can you please provide me the direct link?

    Thanks loads!

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    14
    Sorry for double posting again, but I just noticed that the forum software trimmed blank spaces that I provided in my first post... Actually I need a program to output something like that:

    - - - *
    - - * *
    - * * *
    * * * *

    where ' - ' represents a space...

  5. #5
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Try counting down with a space counter and up with a fill counter, then use two loops, one for the spaces and one for the fills. All in all you'll have two little loops nested in one big loop.
    p.s. What the alphabet would look like without q and r.

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    14
    I came up with something like that, but its not working, can you please help me?

    #include <stdio.h>

    void main()
    {
    int n,i,j,k;
    printf("enter number:");
    scanf("%d", &n);

    for (k=n, k<=n; k++)

    for (j=n; j<=n; j=j-1)
    {
    for (i=1; i<=j; i++)
    {
    printf("*");
    }
    printf("\n");
    }
    printf(" ");
    }

    }

  7. #7
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134
    Hi ok this is a froward triangle to give you an idea:

    Code:
    #include <stdio.h>
    
    int main()
    {
    int line;
    int asterix;
    int space;
    
    for (line=0;line<=5;line++){
                                for (space=4;space <=0;space--){
                                                                printf(" ");
                                                                }
                                for(asterix=0;asterix<=line;asterix++)printf("*");
                                printf("\n");
                                }
    
    
    
    
          system("PAUSE");
          return 0;
    }
    And To All Those Opposed, WELL !!!
    >Deleted< " Looks like a serial no."

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    14
    Hi,

    I really dunno how to thank you... I'm always impressed when someone would take the time and help me, even they don't know me. I really want to be the same person too, to be helpful to anyone... Helping is also learning for me, but I fear that programming ain't my field. I'm more into web design, so if anyone here needs help in this area, let me know, I'll be more than happy to help you guys...

    Thanks a lot GSLR for the code snippet. Now I need to have something like this but which does the reverse, as I pointed out in another post:

    - - - *
    - - * *
    - * * *
    * * * *

    As Brighteyes suggested, there should be a main loop and 2 smaller loops... I tried really hard on this one as well, but couldn't figure it out.. I even tried playing with the code you posted, but in vain... Programming really ain't my cup of tea!

    So if you can please assist me on this one as well.... Thanks a lot!

  9. #9
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    > but its not working
    That's because it's got syntax errors and won't compile. Also, when I said two loops inside another loop, I didn't mean two nested loops, I meant something like this:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int n, i, j, k;
        int space, fill;
        
        printf("enter number:");
        scanf("%d", &n);
    
        space = 2;
        fill = 2;
        
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < space; j++)
                printf(" ");
    
            for (k = 0; k < fill; k++)
                printf("*");
    
            printf("\n");
        }
    
        return 0;
    }
    Now all you need to do is fix the spacing, which shouldn't be difficult if you do what I described in my last post.
    p.s. What the alphabet would look like without q and r.

  10. #10
    Registered User
    Join Date
    May 2003
    Posts
    14
    Hi Brighteyes,

    Thanks a lot! Been finally able to make it!

    Btw, another question, in what font you guys advice me to print my code snippets (hard copy)?

  11. #11
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    If I use hard copy, I'll pick the same font as everyone else if I'm in a group, or just whatever seems easiest to read if it's just me. Play around with it and find what you like best. I usually go with Lucida Console though.
    p.s. What the alphabet would look like without q and r.

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    14
    Never used Lucida Console, will download it and give it a try... I remembered that once my programming teacher advised me to use a particular font to print code snippets since the font has a fixed size for all the letters, and that makes reading, and indentation of your coding looks nicer... But I forgot what font he mentioned... Think I was Arial Unicode MS...

  13. #13
    Registered User
    Join Date
    May 2003
    Posts
    14
    Hi Salem,

    Yes it was courier new actually! Thanks for refreshing my mind!

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    73
    When I post code snippets, I just use whatever the default is for the "(code) (/code)" tags.

    Btw, switch the "(" and ")" with the rectangular brackets.

  15. #15
    Registered User
    Join Date
    May 2003
    Posts
    14
    Originally posted by Nuke
    Btw, switch the "(" and ")" with the rectangular brackets.
    Hi Nuke,

    Can't get you on this one!

Popular pages Recent additions subscribe to a feed