ct1_sols
ct1_sols
Answer the questions in the spaces provided on the question sheets. You may use
the last page of this booklet for your rough work. No other supplementary sheets
will be given to you.
Name
Question: 1 2 3 4 5 Total
Points: 5 5 5 2 3 20
Score:
1. (5 points) Fill in the blanks below. One blank can have ATMOST ONE statement.
[2+1.5+0.5+0.5+0.5=5]
return 0;
1
}
Page 2
#include <stdio.h> Count: 2
int main()
{ Sum: 5
int n = 10, count = 0, sum = 0;
while(--n > 0) n: 0
{ Marking scheme: 2 marks
n /= 2; if all three correct, 1 mark
count++; if one of these is incorrect,
sum +=n; otherwise 0.
}
return 0;
}
4. (2 points) What will be the output of the following programs? [1+1 = 2]
(a)
#include <stdio.h>
int main()
{ Answer: 1 2 3 4 5 6 7 8 9 10
int count = 0;
for(;;)
{
if(count==10)
break;
printf("%d ",++count);
}
return 0;
}
(b)
#include <stdio.h>
int main()
{ Answer:
int num; #0#1#2#3#4#5#6###
for(num=0;num<10;++num)
{
printf("#");
if(num>6)
continue;
printf("%d",num);
}
return 0;
}
5. (3 points) Fill in the blanks. The following code snippet is from a program that takes as
input a stream of integers until the number 0 is entered. It then prints the total number of
even (zero excluded) and odd integers that were input.
#include<stdio.h>
int main()
{
int odd_count=0, even_count=0, num;
printf("\n Enter integers (input 0 to terminate):");
scanf("%d", &num);
Page 3
while(___num != 0__________)
{
if(___num%2 == 0________)
even_count++;
else
odd_count++;
__scanf("%d", &num)_____;
}
printf("\n The number of even numbers entered is %d.", even_count);
printf("\n The number of odd numbers entered is %d.", odd_count);
return 0;
}
Page 4