0% found this document useful (0 votes)
4 views4 pages

ct1_sols

This document is a class test for the Programming and Data Structure course at the Indian Institute of Technology, Kharagpur, conducted on January 31, 2018. It consists of multiple programming questions that require students to fill in blanks, predict outputs, and analyze code behavior. The test has a total of 20 marks, with various sections focusing on C programming concepts.

Uploaded by

ritikorritik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

ct1_sols

This document is a class test for the Programming and Data Structure course at the Indian Institute of Technology, Kharagpur, conducted on January 31, 2018. It consists of multiple programming questions that require students to fill in blanks, predict outputs, and analyze code behavior. The test has a total of 20 marks, with various sections focusing on C programming concepts.

Uploaded by

ritikorritik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Indian Institute of Technology, Kharagpur

Department of Computer Science and Engineering


Class Test 1, Spring 2017-18
Programming and Data Structure (CS 11001 / CS 10001)
Students: Date: 31-Jan-2018
Full marks: 20 Time: 7:00pm–8:00pm

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.

Roll Number Section

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]

/* C program to calculate compound interest */


#include<stdio.h>
#include<math.h>
int main() {
float principal, rate, time, amount, interest;
/* Take principal, rate and time as input from user */
printf("Enter Principal\n");
scanf("%f", &principal);
printf("Enter Rate of Interest\n");
scanf("%f", &rate);
printf("Enter Time in Years\n");
scanf("%f", &time);

/* Calculates Total Amount after time years */


amount = principal * _____pow((1 + rate/100), time)_____;
/* Calculates Compound Interest accrued in time years */
interest = ____amount - principal_____;
printf("After ____%f_____ Years\n", ____time_____);
printf("Total Amount = ___%f______\n", __amount___);
printf("Compound Interest Earned = __%f___", ___interest___);

return 0;

1
}

2. (5 points) What will be the output of the following programs? [3+2=5]


(a)
#include<stdio.h>
int main() Answer: EQUAL
{ EQUAL
float x = 7.52, y = 7.25;
if (x = y) printf("EQUAL\n");
else printf("INEQUAL\n");
if (x == y) printf("EQUAL\n");
else printf("INEQUAL\n");
return 0;
}
(b)
#include <stdio.h>
Answer: 30
int main()
10
{
20
char choice = ‘c’;
(Marking Scheme: give 1-
switch(choice)
mark if only outputs 30,
{
give 2-marks if the output
default: printf("30\n");
matches exactly; otherwise
case ‘a’: printf("10\n");
give 0. Give marks even
case ‘b’: printf("20\n");
if all outputs are in same
}
line.)
return 0;
}
3. (5 points) Consider the following programs. Write the values of count, sum and n at the
end of these programs? [3+2 = 5]
(a)
#include <stdio.h>
int main() Count: 3
{
int n = 10, count = 0, sum = 0; Sum: 5
while(n-- > 0)
{ n: -1
n /= 2; Marking scheme: 1 mark
count++; for each
sum +=n;
}
return 0;
}
(b)

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

[Extra space for rough work]

Page 4

You might also like