Lab2 Upload
Lab2 Upload
Lab2 Upload
C/C++ Programming
Lab 2
Iterations
_____________________________________________________________________________________
1
INTERNATIONAL UNIVERSITY
I. Objectives
Students are require to review theory of the topics before the lab time.
Exercise 1
Write a C program that reads 10 integers. The program should count the number of
positive and negative values among 10 inputs. Print them on the screen. (Use iteration
statements). Zero is neither a positive or a negative number.
Output:
Number of positive: 5
Number of negative: 5
Exercise 2
Write a C program that reads a student grade which is a character. The program should
print the classification based on the grade as:
_____________________________________________________________________________________
2
INTERNATIONAL UNIVERSITY
Grade Classification
A Excellent
B Good
C Fair
D Average
F Weak
Other characters Invalid
After showing the Classification, the program should ask the user to continue to read
another grade or not. by choosing yes (‘y’) or no (‘n’). If yes, continues, otherwise, prints “Exit
program...”.
Output:
Exercise 3
3 5 7
x−x + x −x …
The user should input the value for x and the number of terms
For Example
Output:
_____________________________________________________________________________________
3
INTERNATIONAL UNIVERSITY
Exercise 4
Output:
Factorial of 4= 24
Exercise 5
Output:
Exercise 6
Write a C program that Program to generate a “mystery” number by the computer, that is a
random number from 1 to 100. Then, the user will guess this number by prompting a value.
There are three possible responses:
_____________________________________________________________________________________
4
INTERNATIONAL UNIVERSITY
The game ends when the user guesses the correct number. After that, let the user decide to
replay or not by choosing yes (‘y’) or no (‘n’)
Hint: Include stdlib.h and time.h. Use the following codes to generate a random number:
Bonus Exercise
_____________________________________________________________________________________
5
INTERNATIONAL UNIVERSITY
Write a C program that Program to calculate the sin( x) which is described in series as belows:
3 5 7
x x x
sin ( x )=x− + − +… where x is angle∈radian
3! 5! 7!
The user should input the value for x and the number of terms
For Example
Output:
THE END
_____________________________________________________________________________________