Using 2 for loops

how do I write a code like

*
**
***
****

and so on? I am beginning to learn C++.


Comments

  • : how do I write a code like
    :
    : *
    : **
    : ***
    : ****
    :
    : and so on? I am beginning to learn C++.
    :
    :
    :

    In C++

    #include

    using namespace std;

    int main(void)
    {
    for (int i = 0; i < 4; ++ i)
    {
    for (int j = 0; j < i; ++ i)
    putchar('*');
    puts("

    ");
    }
    return 0;
    }

    in C:


    #include

    int main(void)
    {
    int i, j;
    for (i = 0; i < 4; ++ i)
    {
    for (j = 0; j < i; ++ i)
    putchar('*');
    puts("

    ");
    }
    return 0;
    }

    Basically, the only real difference between C and C++ in that in C you cannot declare varible within for loops.
  • : : how do I write a code like
    : :
    : : *
    : : **
    : : ***
    : : ****
    : :
    : : and so on? I am beginning to learn C++.
    : :
    : :
    : :
    :
    : In C++
    :
    : #include
    :
    : using namespace std;
    :
    : int main(void)
    : {
    : for (int i = 0; i < 4; ++ i)
    : {
    : for (int j = 0; j < i; ++ i)
    : putchar('*');
    : puts("

    ");
    : }
    : return 0;
    : }
    :
    : in C:
    :
    :
    : #include
    :
    : int main(void)
    : {
    : int i, j;
    : for (i = 0; i < 4; ++ i)
    : {
    : for (j = 0; j < i; ++ i)
    : putchar('*');
    : puts("

    ");
    : }
    : return 0;
    : }
    :
    : Basically, the only real difference between C and C++ in that in C you cannot declare varible within for loops.
    :


    Please, stop doing other people's homework, we really don't need to encourage them to get more than 10 posts like this per week. Try to give him a point in the right direction, but please don't provide the whole solution without any effort made from the OP's side.
  • : : : how do I write a code like
    : : :
    : : : *
    : : : **
    : : : ***
    : : : ****
    : : :
    : : : and so on? I am beginning to learn C++.
    : : :
    : : :
    : : :
    : :
    : : In C++
    : :
    : : #include
    : :
    : : using namespace std;
    : :
    : : int main(void)
    : : {
    : : for (int i = 0; i < 4; ++ i)
    : : {
    : : for (int j = 0; j < i; ++ i)
    : : putchar('*');
    : : puts("

    ");
    : : }
    : : return 0;
    : : }
    : :
    : : in C:
    : :
    : :
    : : #include
    : :
    : : int main(void)
    : : {
    : : int i, j;
    : : for (i = 0; i < 4; ++ i)
    : : {
    : : for (j = 0; j < i; ++ i)
    : : putchar('*');
    : : puts("

    ");
    : : }
    : : return 0;
    : : }
    : :
    : : Basically, the only real difference between C and C++ in that in C you cannot declare varible within for loops.
    : :
    :
    :
    : Please, stop doing other people's homework, we really don't need to encourage them to get more than 10 posts like this per week. Try to give him a point in the right direction, but please don't provide the whole solution without any effort made from the OP's side.
    :

    Sometimes knowing the solution to a given problem can help one in understanding the process of devising the solution. However, fair enough I shall change the nature of my replys to such problems in the future, unless they give me bribes.
  • : how do I write a code like
    :
    : *
    : **
    : ***
    : ****
    :
    : and so on? I am beginning to learn C++.
    :
    :

    [blue]You don't even need a nested loop to accomplish this in C++, a single loop can be used in conjunction with the [italic]string[/italic] constructor to create a sequence of '*' characters of the appropriate length.[/blue]

  • : [blue]You don't even need a nested loop to accomplish this in C++, a single loop can be used in conjunction with the [italic]string[/italic] constructor to create a sequence of '*' characters of the appropriate length.[/blue]
    :
    Simple as it may seem to us, to a beginner, strings are somewhat more complicated than loops.
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