/***************************************** ** File: factors.c ** Author: CMSC 201 Students, Sections 0101-0106 ** Date: Sept. 20, 2006 ** E-Mail: mariedj@cs.umbc.edu ** ** prints out the prime factorization of a number *****************************************/ #include int NumFacts (int i, int n); void PrintFactorization (int n); int main () { int n; printf ("Please enter a number to factor: "); scanf ("%d", &n); PrintFactorization(n); return 0; } /***************************************** * Function: PrintFactorization * Usage: * * * * Input: * Output: *****************************************/ void PrintFactorization (int n) { int i, j, factors; i = 2; while ( i <= n ) { factors = NumFacts (i, n); for ( j = 1 ; j <= factors ; j++ ) { printf ("%5d ", i); n = n/i; } i++; } printf ("\n"); } /***************************************** * Function: NumFacts * Usage: * * * * Input: * Output: *****************************************/ int NumFacts (int i, int n) { int count = 0; while ( n%i == 0 ) { n /= i; count++; } return (count); }