Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C++ How can I do a nested for loop for *?

Umm, so I got this assigned for my C++ homework and I don't understand how do it.

// Write a code block that uses nested for-loops (and no

// if-statements or switch-statements) to produce this sequence of

// 4 lines of asterisks (that is, the char value '*'):

// *

// **

// ***

// ****

Can anyone help out?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    The point is the consition part of the second for loop (m < n + 1):

    for(int n=0; n< 4; n++)

    {

    for (int m=0; m< n +1; m++)

    {

    cout << '*';

    }

    cout << '\n';

    }

  • mata
    Lv 5
    1 decade ago

    for (int i = 1; i <= 4; i++) {

    for (int j = 1; j <= i; j++) {

    cout << "*";

    }

    cout << endl;

    }

Still have questions? Get your answers by asking now.