Object

Write a program to print asterisks (*), starting with one increasing one asterisk in the following line until number of asterisks reaches to 10.

Algorithm

  1. Declare integer variables row and column.
  2. Repeat FOR row = 1 to 10 by 1
    • Repeat FOR column = 1 to row by 1
      • Write “*”.
    • [End of inner FOR loop.]
      • Advance a line.
    • [End of outer FOR loop.]
  3. Exit.

Flowchart

C++ Source Code

// program 45
#include<iostream>
using namespace std;

int main()
{
  int row, column;
  for (row = 1; row <= 10; row++) // outer loop
  {
    for (column = 1; column <= row; column++) // inner loop
      cout << "*";

      cout << "\n"; // outside of the second loop, inside the first
  }
  return 0;
}

C Source Code

/*program 45*/
#include<stdio.h>

int main()
{
  int row, column;
  for(row = 1; row <= 10; row++)   			/* outer loop */
     {
     for (column = 1; column <= row; column++)	/* inner loop */
        printf("*");

     printf("\n");	/* outside of second loop, inside first*/
     }
  return 0;
}

Output

*
**
***
****
*****
******
*******
********
*********
**********
Design a site like this with WordPress.com
Get started