{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lab5 - CP202 Lab5 In-Class work 14 DQaddah 1428 18 DQaddah...

This preview shows pages 1–2. Sign up to view the full content.

CP202 – Lab5 14 D’Qaddah 1428 – 18 D’Qaddah 1428 1/2 In-Class work: 1. Type the following program carefully. Compile and run. (1 point) Lab5-sum.c 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h> int main(void) { int x, sum=0, i=0; while (i<5) { scanf(“%d”, &x); sum = sum + x; i = i + 1; } printf(“%d\n”, sum); } 2. Change Lab5-sum.c as follows. Compile and run. (1 point) 6 while (i<5) Write the error message? What does it mean (in Arabic)? Error message: _____________________________________________________________ Meaning: __________________________________________________________________ 3. Change Lab5-sum.c to calculate the sum and average. Compile and run. (1 point) Lab5-sum.c 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h> int main(void) { int x, sum=0, i=0; while (i<5) { scanf(“%d”, &x); sum = sum + x; i = i + 1; } printf(“sum=%d\navegrage=%f\n”, sum, sum/5); } Check the output. What is wrong? (Hint: the literal constant 5 in line 11 is int ). __________________________________________________________________________ CP202 – Lab5 14 D’Qaddah 1428 – 18 D’Qaddah 1428 2/2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4. Change Lab5-sum.c from 2 as follows. Compile and run.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}