Computer Programming Lab # 4
Computer Programming Lab # 4
Objectives:
To understand the programming using iteration statements like while, do-while and for Loop and
jump statements like continue, break, return and goto.
Tasks:
1. Write a program to create Simple Calculator using switch case (the calculator must have
a loop that it could keep on running and ask the user again for input after showing output
from the previous inputs).
2. Write a program that takes a number as input, checks it if it is between 1 and 10
and if it is in valid range your program should output a line containing that number of
adjacent asterisks. On invalid input number, the program should end.
For example, if your program input is 7, it should print *******.
3. Write a program to find Factorial of a number.
4. Write a program to print multiplication table of any number.
5. Write a program to input two integer numbers and display the sum of even numbers
between these two input numbers.
6. Write a program to print all-natural numbers in reverse (from n to 1).
7. Write a program that takes the base and exponent as input and display the result of
power.
8. Write a program that prints your name and registration number 10 times using loop and
on the 5th iteration (run) of your loop it should skip and display this “Mid of loop” and
then continue displaying your name and registration number.
9. Write a program that performs a survey tally on beverages. The program should prompt
for the next person until a sentinel value of –1 is entered to terminate the program. Each
person participating in the survey should choose their favorite beverage from the
following list:
1. Coffee 2. Tea 3. Coke 4. Orange Juice
Sample Run:
Please input the favorite beverage of person #1: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program
4
Please input the favorite beverage of person #2: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program
1
Please input the favorite beverage of person #3: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program
3
Please input the favorite beverage of person #4: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program
1
Please input the favorite beverage of person #5: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program
1
Please input the favorite beverage of person #6: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program
-1
The total number of people surveyed is 5. The results are as follows: