CSC 161 Grinnell College Fall, 2011
 
Imperative Problem Solving and Data Structures
 

asterisk-loop.c: A basic program about nested loops

As a basic program about nested loops, consider the following code that prints rows with increasing numbers of asteriskes. Commentary after the program explains each element of this program.


#include <stdio.h>

int
main()
{
  int i, j;
  
  printf("Program to print rows with increasing numbers of asterisks.\n");

  for (i = 1; i < 11; i++)
    {
      for (j = 0; j < i; j++)
        {
        printf("*");
        }
      printf("\n");
    }

  return 0;
}


Commentary on the asterisk-loop.c program


This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~

created 28 July 2011 by April O'Neill
last revised 29 July 2011 by April O'Neill
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.