how do i print such a program in C using for/while/do while loops?

*
* *
* * *
* * * *

Comments

  • : *
    : * *
    : * * *
    : * * * *
    :


    if you know how to create a for loop then the problem is pretty trivel. Post your best effort and we'll be glad to help you out, but we are not going to do your homework for you. Here is a start.
    [code]
    #include

    int main()
    {
    // put your code here
    return 0;
    }
    [/code]
  • : : *
    : : * *
    : : * * *
    : : * * * *
    : :
    :
    :
    : if you know how to create a for loop then the problem is pretty trivel. Post your best effort and we'll be glad to help you out, but we are not going to do your homework for you. Here is a start.
    : [code]
    : #include
    :
    : int main()
    : {
    : // put your code here
    : return 0;
    : }
    : [/code]
    :


    [code]
    #include

    int main()
    {
    printf(" * ");
    printf(" * * ");
    printf(" * * * ");
    printf("* * * *");

    return 0;
    }

    [/code]
  • : : : *
    : : : * *
    : : : * * *
    : : : * * * *
    : : :
    : :
    : :
    : : if you know how to create a for loop then the problem is pretty trivel. Post your best effort and we'll be glad to help you out, but we are not going to do your homework for you. Here is a start.
    : : [code]
    : : #include
    : :
    : : int main()
    : : {
    : : // put your code here
    : : return 0;
    : : }
    : : [/code]
    : :
    :
    :
    : [code]
    : #include
    :
    : int main()
    : {
    : printf(" * ");
    : printf(" * * ");
    : printf(" * * * ");
    : printf("* * * *");
    :
    : return 0;
    : }
    :
    : [/code]
    :

    He needed to use some kind of loop:
    [code]
    #include

    int main()
    {
    char *p[4];
    p[0] = " * ";
    p[1] = " * * ";
    p[2] = " * * * ";
    p[3] = "* * * *";

    int i,j;
    for(i=0;i<4;++i){
    j=0;
    do{j++}while(i!=j);
    while(i=j)
    puts(p[j]);
    }

    return -1;
    }

    [/code]
  • : He needed to use some kind of loop:


    Oops, my bad. Here is the complete code in that case:

    [code]
    #include

    int main()
    {
    for(;;)
    {
    while(0x01&0x01 ? 576/3*3/0*34 : 2%45/5)
    {
    printf(" * ");
    printf(" * * ");
    printf(" * * * ");
    printf("* * * *");
    }
    }

    return 0;
    }
    [/code]
  • very funny :) you should submit that here

    http://www0.us.ioccc.org/main.html

    But, unfortunately, that will only confuse the OP.
  • [b][red]This message was edited by chinuchinu at 2006-9-5 7:52:43[/red][/b][hr]
    [b][red]This message was edited by chinuchinu at 2006-9-5 7:52:10[/red][/b][hr]
    GUYS!
    i am a beginner and i really dont know how to do this. I know how to print :

    *
    **
    ***
    ****

    but not:
    |||||*
    ||||* *
    |||* * *
    ||* * * *

    PLEASE NOTICE THE DIFFERENCE.(Ignore the |s) The pattern is important.




  • : [b][red]This message was edited by chinuchinu at 2006-9-5 7:52:43[/red][/b][hr]
    : [b][red]This message was edited by chinuchinu at 2006-9-5 7:52:10[/red][/b][hr]
    : GUYS!
    : i am a beginner and i really dont know how to do this. I know how to print :
    :
    : *
    : **
    : ***
    : ****
    :
    : but not:
    : |||||*
    : ||||* *
    : |||* * *
    : ||* * * *
    :
    : PLEASE NOTICE THE DIFFERENCE.(Ignore the |s) The pattern is important.
    :
    :
    :
    :
    :

    OK, here's some real help:

    Count the number of *s above.
    See a pattern?

    Count the number of |s in the lines above.
    See a pattern?

    Use this information to produce the program.
  • and you need two loops, not one. The inner loop will print the spaces, the outer loop prints the stars.
  • : and you need two loops, not one. The inner loop will print the spaces, the outer loop prints the stars.
    :

    Hmm, how could that be done?

    Wouldn't he need 3 loops?: one outer, one that loops the spaces, and one that loops the stars
  • : : and you need two loops, not one. The inner loop will print the spaces, the outer loop prints the stars.
    : :
    :
    : Hmm, how could that be done?
    :
    : Wouldn't he need 3 loops?: one outer, one that loops the spaces, and one that loops the stars
    :

    you are right -- the outermost loop will count the number of rows (or lines) in the triangle.
  • : very funny :) you should submit that here
    :
    : http://www0.us.ioccc.org/main.html
    :


    Find the hidden run-time error :-)



    : But, unfortunately, that will only confuse the OP.

    That was my intention, since he is too stupid to understand "we don't do your homework for you". This is the 3rd or 4th time he is begging for code.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories