/* * factor.c * Chapter7 * By John Stile * Purpose: * Write a program called factor.c that produces the produces * the following factor output for a series of numbers using * nested for loops. * * 1!= 1=1 * 2!= 2*1 = 2 * 3!= 3*2*1 = 6 * ... * 10!= 10*9*8*7*6*5*4*3*2*1 = 3628800 */ #include // include stdio.h functions when compiling #define NUM 10 // define a macro, where NUM will be reaplced by 10 int main(void) // header for function main { int xx,yy ; // declare 2 intigers float factorial; // declare a float for ( xx=1; xx<=NUM; xx=(xx+1) ) // outer loop, count from 1 to 10 { factorial=1; // zero out factorial printf("%d!=\t",xx); // first part of output, current number for (yy=xx; yy>0; yy=(yy-1) ) // cycle through 1 to current xx { printf("%d*", yy); // print each yy with a * after the digit factorial=(factorial*yy); // calcuate the factoria by adding another mutilplyer each iteration } printf("\b"); // print the backspace, this removes the * from the final yy for this iteration. printf(" = %.0f\n", factorial); // print the final result } return 0; // return 0 to calling function }