You are on page 1of 2

Paper Code BCS-80 Roll No.

B.Tech. (CSE)
Odd Semester (Sem.-I)
Minor Examination 2018-2019
Programming in C
Time: 2 hrs Max. Marks: 20

Note: Attempt all questions. Each question carries equal marks.

Q.1 Attempt any three of the following; Q.1 (a) is compulsory.

(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.

Q.2 Attempt any two of the following; Q.2 (a) is compulsory.

(a) Write a program in C to print the following pattern: 4

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

Number Character Output

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

i) void main ( ) ii) void main( )


{ {
int x = 1, y, z = 027; int x = 1, y = 0, z = -1;
y = ++x + ++x + ++x; printf(“%d”, ++x && ++y || ++z);
printf(“%d%d”, y, ++x + ++x + ++x); printf(“%d%d%d”, x, y, z);
printf(“%d%i”, z, z ); }
}

Q.3 Attempt any two of the following; Q.3 (a) is compulsory.

(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.

𝑥−1 1 𝑥−1 2 1 𝑥−1 3 1 𝑥−1 4 1 𝑥−1 5


i) ( ) + ( ) + ( ) + ( ) + ( ) + . . . . . . . .
𝑥 !2 𝑥 !3 𝑥 !4 𝑥 !5 𝑥
i
p 𝑥 p(p−1) 𝑥
ii) 1 − ( ) ( ) + (
!1 𝑞 !2
) (𝑞) 2 − . . . . . . . . .

(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

i) void main ( ) ii) void main ( )


{ {
int x=4, y=3, z; int d = 3;
z=x-- -y; if (d = = 3.0)
printf(“%d%d%d”, x, y, z); printf("%d", d);
, , , , else
while( x < y )
printf("%f", 3.0);
printf(“%d”, x-8);
printf("%d", printf("Mmmut"));
}
}

You might also like