Programs
- Declare an integer variable i, assign it a value of 17, and print a message (e.g. "my number is: ") and the value as we did in class.
- Copy the first program using the shell command "cp". Instructions on how to use it are in Anderson. In the new copy, change the name of the variable i to i3. Be sure to change the name everywhere the variable is used. Compile and run to show it works (be sure to do this in your script!). Now edit the file again and change the name to 3i. Compile while scripting. Question: What error message do you get?
- Write a new program with three variables of type int: i, j, and result. Have your program calculate the formula:

for i=3 and j=4. Your code will not look or work exactly like the formula shown - think, and test your ideas. Your program should print the values of i and j, and the calculated value of result. Use a single printf statement to print all three.
- Copy the first program using the shell command ``cp''. In the new copy, change the value you assign to the integer i to 39.25 (which is not an integer). Questions: What does the program print? What do you think happened? What will happen for 31.99?
- Declare a variable named f of type "double" instead of type integer. Assign it the value 100.001. Print it out with a nice message, but change the format specifier from %d to %lf (that is lower case LF). You should see the complete number when you compile and run. Now change to the format specifier for an integer, %d, but do not change the type of the variable. What gets printed when you compile and run? Show it in your script. After you test this, change your program back so that it prints correctly, compile and show in your script.
- Declare an integer variable i, assign it the value 5. Now write two print statements using the integer format specifier: print the result of dividing i by 2 in the first, and dividing i by 2.0 in the second. Then write a third print statement that uses a double format specifier to print i divided by 2. Explain the results in your comments. (If you don't understand the result you are seeing, print some other calculations too. Play around until you understand which cases cause problems.)
- Declare a double variable x, assign it the value 5. Now write two print statements using the double format specifier: print the result of dividing x by 2 in the first, and dividing x by 2.0 in the second. Then write a third print statement that uses an integer format specifier to print x divided by 2. Explain the results in your comments.
- The percent sign % is an operator in C. Pronounce it "mod". Using multiple calculations and print statements, show the value of 1%3, 2%3, 3%3, 4%3, 5%3, and 6%3 in one run of a program.
- Write a program to calculate the area of a circle. Have the program prompt the user and take integer input using "scanf" for the radius. Assume pi is 3.14159, and define a constant for pi.
- Find and review the Unix shell commands ls, cd, rm, mv, and mkdir in Andersen. Practice making one or more directories, moving into them, listing the files and directories there, and then moving back out. Use rmdir to remove any practice directories you have made. (Be careful!) Then create a directory ``cisc105''. Move into it and create directories ``lab00'' and ``lab01''. Then move all your lab files from your root directory (where you are if you just type ``cd'' with no arguments and hit return) to the appropriate lab directory using mv. List the files in your three new directories.
Read the instructions in this lab very carefully. You will lose points for not following instructions. We have too many students to allow us the time to grade any "creative" responses. Take creative programs to the instructor during office hours for discussion.
You should have a total of 9 programs named lab01.1.c to lab01.9.c. Make a single script file (see lab00 for the instructions) where you cat, compile, and run each one in its final form (if it didn't compile, don't run it in the script - mark the place in the printed script file with a marker so it stands out). After all files have been run in the script, use ls and cd to show your new directories and their files in the script.
Submit all ten files on WebCT before 11:55 p.m. Thursday, and give the paper version to your TA at the beginning of your Friday lab (or in lecture Friday if you have a Wednesday lab). Note: cat, compile, and run each program in order! Do not cat all programs, then compile, etc.