Professional Documents
Culture Documents
B.Tech. (CSE)
Odd Semester (Sem.-I)
Minor Examination 2018-2019
Programming in C
Time: 2 hrs Max. Marks: 20
(a) Write a program in C for a matchstick game being played between the computer and a user. Your 4
program should ensure that the computer always wins. Rules for the game are as follows:
1. There are 21 matchsticks.
2. The computer asks the player to pick either 1, 2, 3, or 4 matchsticks at a time.
3. After the person picks, the computer does its picking.
4. If, user picks n, the computer picks 5-n.
5. So, if we reduce the total by 5 each round, the sequence will go 21 16 11 6 1.
6. Whoever is forced to pick up the last matchstick loses the game.
(b) Write a program in C to find the all Pythagorean triplets less than 200. 2
(c) Is switch a replacement of if ? Justify your answer. Also find the output of following program and give 2
the reason of output.
void main ( )
{
char d= -256; int i , j;
if(d)
{
for( i = 0; i<=128; i++)
, ,
printf(“%d”, d );
}
else
{
, ,
for(i<7; j = d ; j=0)
printf("%d", d);
}
}
(d) Write a program in C to compare three numbers and print the middle number among them using nested 2
if-else method only, here numbers are entered by user.
a b c d e
p q r s f
o x y t g
n w v u h
m l k j i
(b) Write a program in C to show the nesting of switch statement of following table: 2
1 R RED
B BLUE
2 R RAT
B BAT
(c) What will be output of the following programs? Discuss the reason and show each step. 2
(a) If, x, p, q are inputs through the keyboard, write a program in C to calculate the sum of first seven 4
terms of the following series.
(b) Write a program in C to check whether a given number is Armstrong number or not. Your program 2
should works for any number have any digits.
(c) What will be output of the following programs? Discuss the reason and show each step. 2