C examples for Statement:for
Generating a table of Triangular Numbers, output as a table
#include <stdio.h> int main (void) { int n, triangularNumber; printf ("TABLE OF TRIANGULAR NUMBERS\n\n"); printf (" n Sum from 1 to n\n"); printf ("--- ---------------\n"); triangularNumber = 0;/*from w w w. j a v a 2 s. c o m*/ for (n = 1; n <= 10; ++n) { triangularNumber += n; printf ("%2i %i\n", n, triangularNumber); } return 0; }