Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

chinuchinuchinuchinu Posts: 13Member
*
* *
* * *
* * * *
«1

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    : *
    : * *
    : * * *
    : * * * *
    :


    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]
  • LundinLundin Posts: 3,711Member
    : : *
    : : * *
    : : * * *
    : : * * * *
    : :
    :
    :
    : 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]
  • IDKIDK Posts: 1,784Member
    : : : *
    : : : * *
    : : : * * *
    : : : * * * *
    : : :
    : :
    : :
    : : 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]
  • LundinLundin Posts: 3,711Member
    : 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]
  • stoberstober Posts: 9,765Member ✭✭✭
    very funny :) you should submit that here

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

    But, unfortunately, that will only confuse the OP.
  • chinuchinuchinuchinu Posts: 13Member
    [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.




  • IDKIDK Posts: 1,784Member
    : [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.
  • stoberstober Posts: 9,765Member ✭✭✭
    and you need two loops, not one. The inner loop will print the spaces, the outer loop prints the stars.
  • IDKIDK Posts: 1,784Member
    : 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
  • stoberstober Posts: 9,765Member ✭✭✭
    : : 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.
«1
Sign In or Register to comment.