Due: 12:00 Noon Thu Sept 19
You are to create a number of files, as directed below, and then submit them electronically on host lectura.cs.arizona.edu using the command
Please follow the directions below carefully: submissions that don't follow directions will be penalized heavily.
Note:
Under csh and tcsh you can check the exit status of a command or program cmd by typing the command echo $status immediately after the execution of cmd. A program can exit with status n by executing the system call exit(n), or -- in the function main() only -- executing the statement return n.
Recall that for a right-angled triangle, the square on the hypotenuse equals the sum of the squares on the other two sides; and that for triangles in general, the sum of the lengths of each pair of sides is greater than the length of the third side.
You should make sure you check that the values entered make sense (i.e., are non-negative): if they don't, your program should print an appropriate error message and exit with status -1.
Write a program, in a file perfect.c, that reads in integer values, one per line, from stdin, until an end-of-file is encountered; and for each value N so read, prints out `N is perfect' if N is a perfect number, and `N is not perfect' if it is not. You may assume that the input contains only positive numbers (i.e., not anything like abc or -2).
For example, given the input sequence
Write a C program, in a file goldbach.c, that reads in a single number N from stdin and verifies Goldbach's Conjecture for all even numbers upto (and including) N. For each even number k between 4 and N (inclusive), your program should print out three numbers using the statement
printf( "%d %d %d\n", k, a, b ); /* numbers separated by a single space */where a and b are prime numbers such that a+b = k.
To simplify grading, we will assume the following restrictions on the format of your output:
12 5 7and not
12 7 5.
24 = 5 + 19 = 7 + 17.In this case, print only the pair of primes where the first (smaller) value is the smallest. Thus, in the example above, since 5 < 7, you should print
24 5 19and not
24 7 17.