C Programming Homework #3: Prime Factorization

Due: Monday, February 8, 2016

This week continue reading in Lesson #6, Lesson #7, and Lesson #8. This is the same reading as for last week. Lesson #9 contains useful information on while loops and compound conditions. Some of that material in that lesson we'll cover next week.

  1. Using the prime number checking program as a basis, write a program that prints the prime factorization of a given number. The prime factorization of N is the (unique) set of primes that when all multiplied together give N. Some of the primes might be repeated. For example the prime factorization of 12 is 2*2*3. The prime factorization of 100 is 2*2*5*5.

    To do this, find the first prime factor of N (the first factor is definitely prime so you don't need to check for primality) and print it. Then divide N by the factor found and repeat (you might find a while loop useful. You can print each factor on a line by itself.

  2. For the final version of this program, count the number of times each factor occurs and print that number with each factor. For example, given 100 output:

      2^2
      5^2
    

Submit your program to Moodle (the .c file). Be sure it includes a comment block at the top that includes your name, the name of the file, the date, and a brief description of what the program does..


Last Revised: 2016-02-01
© Copyright 2016 by Peter C. Chapin <PChapin@vtc.vsc.edu>