Comp 122 Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

COMP122 ASSIGNMENT 20/7/2021

1. In the main() function, write a program that: (5marks)


A. declares two variables
B. initializes them to the numbers 6.1 and 17.8
C. adds them together
D. prints the sum of the two
E. stops.
2. Using C language, write a whole program that prompts the user for a value, reads the
value into a variable, then prints the number out and stops. (5marks)
3. Using C language, write code fragments that will generate exactly the output shown.
Follow the instructions carefully. DECLARE ANY VARIABLES YOU NEED. You may
write next to the output so that you have more space. A. Write a loop to generate this
output: (5marks)
11 12 13 14 15
4. Using C language, write a for loop to generate this output: (5marks)
15 V
14 V
13 V
12 V
11 V
5. Using an array, write a whole program that prompts the user to input student’s marks, say
for 20 students. Then computes and displays the average mark. (6marks)
6. Write a whole program that prompts the user to input values to an array which was
declared as; myV[3][4]. Then outputs the values but jumping the 7th value. (6marks)
7. Using C language, write a loop to generate this output: (5marks)
-5 0 5 10 15
8. Using C, write a switch statement that will print “Red” for input integers0-3; “Green” for
4-7; “yellow” for 8-11; and “purple” for any other integer. You may not use more than
four different cases. Assume the input is already in the declared integer variable “input”.
(10marks)
9. Using C, write a whole program that behaves as follows: Prompt the user for an integer,
fifty-one times. Then show the user the average of those numbers, the highest number,
and the lowest number. (8marks)
10. Write a whole program that behaves as follows: Prompt the user for an integer, fifty one
times. Each time through the loop, show the highest number so far, the lowest number so
far, and the average of all input so far. (10marks)
11. Using C, write a program that uses gets and puts to input and display your names and
age. (4marks)

********************************************************************

You might also like