Docsity

Quiz Solutions for CMSC 106, Fall 2007 - Quiz #2, Quizzes of Computer Science

Toggle sidebar
bg1
Name (printed):
Student ID #:
Section # (or TA’s:
name and time)
CMSC 106 Quiz #2 Fall 2007
1. [15 pts.] Give the output produced by the following C program:
#include <stdio.h>
#define SIZE 12
#define NUM 2.25
main(){
int a, b=5; float c=2.5, d;
a = SIZE + b;
printf("%d, %d, %d and %d\n",a,b,a/b,a%b);
c += c * 2;
d = a + b / 2;
printf("%.1f, %.1f and %.1f\n",c,d, NUM*3);
return 0;
}
17, 5, 3 and 2
7.5, 19.0 and 6.8
(over )
pf2

Partial preview of the text

Download Quiz Solutions for CMSC 106, Fall 2007 - Quiz #2 and more Quizzes Computer Science in PDF only on Docsity!

Name (printed):

Student ID #:

Section # (or TA’s: name and time)

CMSC 106 Quiz #2 Fall 2007

  1. [15 pts.] Give the output produced by the following C program: #include <stdio.h> #define SIZE 12 #define NUM 2. main(){ int a, b=5; float c=2.5, d; a = SIZE + b; printf("%d, %d, %d and %d\n",a,b,a/b,a%b); c += c * 2; d = a + b / 2; printf("%.1f, %.1f and %.1f\n",c,d, NUM*3); return 0; }

17, 5, 3 and 2

7.5, 19.0 and 6.

(over )

  1. [15 pts.] Write a complete C program which will request and read three exam grades from the standard input. You may assume that the userwill enter positive floating point numbers for each of these exam grades. Your program must find the sum and the average of those three grades. The sum and the average must be written in the same line of output in a complete sentence. Your program need not contain any comments but should be written neatly and use logical indentation.

#include <stdio.h>

int main(){ float ex1, ex2, ex3, sum, average; printf("give three exam grades: "); scanf("%f %f %f", &ex1, &ex2, &ex3); sum = ex1 + ex2 + ex3; average = sum/s; printf("The sum is %.1f and ", sum); printf("the average is %.1f.", average);

return 0; }