CS1101C Lab 2 (Odd Week)

Fundamental Theorem of Arithmetic

The deadline for this lab question is Friday 6 October 2006, 23:59:59 hours.

The name of your C program file must be called fta.c, files with any other name will not be marked.

Preliminary

In the fundamental theorem of arithmetic, every positive integer greater than one can be expressed uniquely as a product of primes apart from their rearrangement. The following are examples of numbers expressed as products of increasing primes.

100 = 2 x 2 x 5 x 5.

37 = 37. // since 37 is itself prime

9699690 = 2 x 3 x 5 x 7 x 11 x 13 x 17 x 19.

The Task

Your task is to write a program fta.c that accepts a number and determine its product of increasing primes. The number entered by the user will always be greater than one.

Assuming that the executable is fta, a sample run of the program is shown below. User input is denoted in bold.

$ gcc -Wall fta.c -o fta
$ ./fta
Enter a number: 100
The product of primes is 2 x 2 x 5 x 5.

$ ./fta
Enter a number: 5
The product of primes is 5.

$ ./fta
Enter a number: 37
The product of primes is 37.

$ ./fta
Enter a number: 12345
The product of primes is 3 x 5 x 823.

$ ./fta
Enter a number: 1101
The product of primes is 3 x 367.

$ ./fta
Enter a number: 9699690
The product of primes is 2 x 3 x 5 x 7 x 11 x 13 x 17 x 19.

$

Points to Note


This document, index.html, has been accessed 22 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 18 different hosts have accessed this document in the last 445 days; your host, 216.73.216.39, has accessed it 1 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.