The purpose of this assignment is to get you started with writing some simple C programs.
For some of the problems below, you need to read in integer values from stdin. You’ve seen in class how you can use the library function scanf() to do this. Remember %d is the code to use in the format string to read a decimal (integer) number. (For example, scanf(“%d”, &num);)
1. Your C code should adhere to the coding standards for this class as listed in the Documents section on the Resources tab for Piazza. 2. Your programs should indicate whether or not they executed without any problems via their exit status, i.e., the value returned by the program when it terminates:
Execution Exit Status
Normal, no problems 0
Error or problem encountered 1 3. Under bash you can check the exit status of a command or program cmd by typing the command “echo $?” immediately after the execution of cmd. A program can exit with status n by executing “exit(n)” anywhere in the program, or by having main() execute the statement “return(n)”. 4. Remember your code will be graded on lectura using a grading script. You should test your code on lectura using the diff command to compare your output to that of the example executable.
5. To get full points your code should compile without warnings or errors when the -Wall flag is set in gcc
Example executables of the programs will be made available. You should copy and run these programs on lectura to test your program’s output and to answer questions you might have about how the program is supposed to operate. Our class has a home directory on lectura which is:
You all have access to this directory. The example programs will always be in the appropriate assignments/assg#/prob# subdirectory of this directory. They will have the same name as the assigned program with “ex” added to the start and the capitalization changed to maintain camelback. So, for example, if the assigned program is theBigProgram, then the example executable will be named exTheBigProgram. You should use the appropriate UNIX commands to copy these executables to your own directory.
So, for this assignment, the paths to the example executables are:
/home/cs352/fall18/assignments/assg1/prob1/exIsFib /home/cs352/fall18/assignments/assg1/prob2/exSumDigits /home/cs352/fall18/assignments/assg1/prob3/exSumSquares
Your program’s output to stdout should match exactly the output to stdout of the example executable. You should test this by redirecting stdout from both your program and the example executables to a file, and then using the UNIX diff command to compare the outputs. There should be no differences. For example, you should do something like: