Generates a table of factorials. - C Statement

C examples for Statement:for

Description

Generates a table of factorials.

Demo Code

#include <stdio.h>

int main (void){
    int factorial;

    printf ("  n         n!   \n");
    printf ("-----   ----------\n");

    factorial = 1;//ww w .  j a  va  2  s  .c  o  m

    for (int n = 1; n <= 10; n++ ){
        factorial *= n;
        printf (" %2i       %7i \n", n, factorial);
    }

    return 0;
}

Result


Related Tutorials