Atılım University Computer Engineering Department
Atılım University Computer Engineering Department
WARNINGS
It is forbidden to bring electronic data storage equipments (e.g. mobile phone, MP3 player, flash disk etc.)
to exams.
Students who either cheat, attempt to cheat or provide a help to other(s) in cheating, get 0 (zero) grade
from the entered examination. Also, based on the regulations, a disciplinary action will be taken.
Q1 Q2 Q3 Q4 Q5 Total
(50pts.) (15 pts.) (10 pts.) (10 pts.) (15 pts.) (100pts.)
1
Q1 (50 pts / 5 pts. each). Multiple-choice questions, mark all the answers to the first page.
3. What type of punctuation marks are used to form and enclose compound statements?
√a) {} b) () c) [] d) /* */
6. Which of the following logical expressions has the value false if a and b have been declared as
follows ?
int a=5, b=2;
a) (a >= b)&&(b != 0) b) (a % b)||(b == 0) √c) (b - 2 != 0) d) 1 || !0
10. The format identifier %lf is used for _____ data type.
a) loaf b) int c) char √d) double
2
Q2 (3 pts. each). Evaluate each of the following expression. (4 marks for each correct answer. True or
false is acceptable in place of 1 and 0 respectively)
Q3 (10 pts). Trace the following C program and write down the output into the output area. (Hint: Each
character or digit should be written in a single cell).
#include <stdio.h>
Output:
#include <math.h>
#include <stdlib.h>
8 4
#define MAX 8.768
4 5 . 6 7 0
int main(void) 8 . 7 7
{ int m = 84; 3 . 0
char my_ch = 'a';; a
double p = 45.67;
printf("%-5d\n", m);
printf("%7.3f\n", p);
printf("%5.2f\n", MAX);
printf("%0.1f\n", sqrt(9));
printf("%5c\n", my_ch);
system("PAUSE");
return(0);
}
3
Q4 (10 pts.) Rewrite the following code segment using “switch” statement.
if(ch=='A' || ch=='a')
{
area=side*side;
printf("Area is %d", area);
}
else
printf("Wrong input!");
switch (ch)
{
case 'A':
case 'a':
area=side*side;
printf("Area is %d", area);
break;
case 'P':
case 'p':
perimeter=4*side;
printf("Perimeter is %d", perimeter);
break;
default:
printf ("Wrong input!");
}
Q5 (15 pts). A company gives 5% salary increase to its workers whose salaries are less than 1500 TL, and
3% salary increase to the other workers. The workers who have been working in the company for at least 5
years get an extra 1.5% increase on their current salary regardless of the amount of their pay.
Write a complete C program for this problem using appropriate selection statements. Assume all salary-
related variables to be used are real numbers.
Sample Run:
Please enter current salary in TL: 1000.0
Please enter number of years worked: 6
The new salary with increase is calculated as 1065.00 TL
4
/* Variations of this solution are possible using different conditional
statements */
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
double salary, /* input salary */
new_salary; /* output increased salary */
int num_years; /*num of years worked */