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

The solutions for quiz #2 of the cmsc 106 course during the fall 2007 semester. The quiz includes two programming questions. The first question asks for the output of a given c program, and the second question asks for writing a c program to read and calculate the sum and average of three exam grades.

Typology: Quizzes

Pre 2010

Uploaded on 07/30/2009

koofers-user-sdi
koofers-user-sdi 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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; }