Note
- Work on an request by yourself without sharing the answer to a classmate. (It is great that students study together but an request is an individual task. It is not a group project.)
- Start to do an request early and ask the teacher if you have a question.
- Add a comment with your name at the top of your source code
- Put all your files that you want to submit into one zip file
1. Please save the program with the name ‘cal.c’
Write a program to input two integer values and out their sum and their difference. A sample run off the program follows. The user input is represented in boldface in the sample run. (page. 56, C by Discovery 4th edition, by Foster & Foster)
1 | Example: |
2. Please save the program with the name ‘guess.c’
Write a C program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. (C by discovery)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Welcome to the game of Guess It!
I will choose a number between 1 and 200.
You will try to guess that number. If you guess wrong, I will tell you if you guessed too high or too low.
You have 5 tries to get the number.
OK, I am thinking of a number. Try to guess it.
Your guess? 50
Too high!
Your guess? 12
Too low!
Your guess? 112
Too high!
Your guess? 250
Illegal guess. Your guess must be between 1 and 200.
Try again. Your guess? 30
**** CORRECT ****
Want to play again? y
Ok, I am thinking of a number. Try to guess it.
Your guess? 58
**** CORRECT ****
Want to play again? n
Goodbye, It was fun. Play again soon.
The following code will print out a random generator between 1-100 ten times.1
2
3
4
5
6
7
8
9
10
11
12
int main(){
int c, n;
printf("Ten random numbers in [1,100]\n");
for (c = 1; c <= 10; c++)
{
n = rand() % 100 + 1;
printf("%d\n", n);
}
return 0;
}