2020-21
2020-21
1
2
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
#include<stdio.h>
main()
{
char a=70,b=105;
if(a== 'E'+1)
{
if (b=='k'-1)
printf("CAN YOU FIND ME\n");
else if(b=='k'-2)
printf("HOPE YOU FOUND ME\n");
else
printf("YES\n");
if(a=='G'-1)
printf("CANNOT YOU FIND ME\n");
else
printf("NO\n");
}
else
printf("YES I FOUND YOU\n");
}
Ans
a.
HOPE YOU FOUND ME
CANNOT YOU FIND ME
b.
CAN YOU FIND ME
CANNOT YOU FIND ME
c.
CAN YOU FIND ME
NO
1
d.
CAN YOU FIND ME
CANNOT YOU FIND ME
#include<stdio.h>
void main(){
int i=11,j=12,num;
num=(++i + ++j + i+j);
printf("%d %d %d",num,i,j);
}
Ans:
a. 46 11 12
b. 11 12 46
c. 50 12 13
d. 46 12 13
#include<stdio.h>
void main()
{
int i=6;
printf("%d",i+++++i);
}
Ans:
a. 6
b. 7
c. 5
d. COMPILE ERROR
#include <stdio.h>
int main()
{
int n = 6;
while (n > 0)
{
n--;
if (n == 4)
continue;
printf("%d\t", n);
}
}
Ans
5 3 2 1 0
5 4 3 1 0
6 5 3 2 1 0
2
6 5 3 2 1
#include<stdio.h>
int main()
{
int a=-2, b=4, c=-4,d;
d = ++a + ((a!=b) > c);
printf("%d %d %d %d",a,b,c,d);
}
Ans:
-1 5 -4 1
-1 4 -4 0
-2 4 -4 0
-1 0 -4 -4
6. int a = 4, b = -3, c = 2, d = 3, e = -3, res = 0;
res= _______
a. 0
b. 1
c. 2
d. 3
#include <stdio.h>
int main()
{
switch(5/2)
{
case 0: printf("C ");
case 1: printf("Java ");
case 2: printf("Python ");
case 3: printf("Lisp "); break;
case 4: printf("C# ");
default:printf("Pascal ");
}
return 0;
}
a. Python C#
b. Python Lisp
c. Python Lisp C#
d. Python Pascal
#include <stdio.h>
#define TRUE 1
3
int main()
{
if(TRUE)
printf("1");
printf("2");
else
printf("3");
printf("4");
return 0;
}
a. 1
b. 12
c. 3
d. Compile time Error
#include<stdio.h>
int main()
{
int i = 5, j = 6, k = 7;
if(--i > ++j == --k)
printf("%d %d %d", i++, ++j, --k);
else
printf("%d %d %d",--i, j++, k++);
return 0;
}
a. 267
b. 376
c. 276
d. 367
#include <stdio.h>
int main()
{
int amount=10;
if(amount==10)
{
printf("Happy...");
break;
printf("Sad");
}
else
{
printf("All ok");
}
return 0;
}
4
a. Happy
b. Sad
c. All ok
d. Compile error
Error: break
Reason: misplaced break/ illegal break
A break statement can be used with looping and switch statements.
5
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
#include<stdio.h>
int main()
{
int a[3] = {20,30,40};
a[0]++;
int i=0;
while(i<3)
{
printf("%d ", i[a]);
i++;
}
}
ii. Which loop guarantees to execute at least one time, give reason? 1+1=2
iii. Find the error in the following code and give reason: 1+1=2
1
{
if(a>0)
printf("Number is positive");
else if(a<0)
printf("Number is negative");
else
printf("Number is zero");
}
Q. 2 What is the output of the following programs?
i. #include<stdio.h> 4
int main()
{
int a=3,b=8,c;
c = a + b%a+b/a*a;
while(a+b < 16)
{
a *=2;
b--;
if(a==c)
break;
}
printf("b=%d c=%d\n",b,c);
return 0;
}
ii. #include<stdio.h> 4
int function(int a);
main()
{
function(10);
return 0;
}
function(int a)
{
int i;
for(i=1;i<a;i++)
{
if(i==9)
{
break;
}
else
printf("\t%d",i);
}
}
2
Q. 3 Write a C program to initialize an array of 10 elements and fill the array with values 8
from the user. Find two elements in array such that the difference between them is
the largest.
Print both the elements, their indexes and the difference value.
NOTE: USE TWO NESTED LOOPS. Do not use the conventional method of finding
the minimum element and maximum element and find their difference.
Sample output is given below:
Q. 4 Write a C program which inputs two numbers and passes them to a function. Function 8
finds the reverse of the two numbers and prints the bigger among the reversed numbers.
If reverse of both the numbers are same it prints that both are equal.
Eg. 1
Enter any two numbers:567 974
Reverse of 1st Number: 765
Reverse of 2nd Number: 479
Reverse of First Number is bigger: 765
Eg. 2
Enter any two numbers:567 567
Reverse of 1st Number: 765
Reverse of 2nd Number: 765
Reverse of First Number is bigger: 765
Reverse of Both the Numbers are equal
3
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
#include<stdio.h>
int main()
{
int a[4] = {10,20,30,40};
++a[1];
int i=0;
while(i<4)
{
printf("%d ", ++i[a]);
i++;
}
}
ii. The continue statement cannot be used inside ________________, while the break 1+1=2
statement can be used. What will happen if there is no break statement?
iii. Find the error in the following code and give reason. 1+1=2
1
void check(int a)
{
if(a%i==0)
printf("%d is divisble by %d", a, i);
else
printf("%d is not divisble by %d", a, i);
}
i. #include<stdio.h> 4
int main()
{
int x=3,y=3,z;
z=x++ > y ? 6:7;
do
{
x++;
y +=2;
if(x+y>4)
continue;
} while(x+y < 9);
z = y%4+x;
printf("y=%d z=%d\n",y,z);
return 0;
}
ii. #include<stdio.h> 4
int function(int a);
main()
{
function(10);
return 0;
}
function(int a)
{
int i;
for(i=a;i>0;i--)
{
if(i==2)
{
break;
}
else
printf("\t%d",i);
}
}
2
Q. 3 Write a C program to initialize an array of 10 elements and fill the array with values 8
from the user. Find two elements in array such that the sum of them is the largest.
Print both the elements, their indexes and the sum value.
NOTE: USE TWO NESTED LOOPS. Do not use the conventional method of finding
two largest numbers and adding them.
Sample output is given below:
Q. 4 Write a C program which inputs two numbers and passes them to a function. Function 8
finds the sum of digits of each number and prints the bigger among the them. If sum
of digits of both the numbers are same it prints that both are equal.
Eg. 1
Enter any two numbers:125 132
Sum of digits of 1st Number: 8
Sum of digits of 2nd Number: 6
Sum of digits of First Number is bigger: 8
Eg. 2
Enter any two numbers:125 125
Sum of digits of 1st Number: 8
Sum of digits of 2nd Number: 8
Sum of digits of Both the Numbers are equal
3
Name
Date
1.
A 83
B 81
C 82
D 84
2.
A 1110 0010
B 1100 0010
C 1010 0010
D 1111 0010
3.
A 131071 to 131071
B 131072 to 131072
C 131072 to 131071
D 131073 to 131073
4.
A 7A9E
B 7A9F
C 7B9E
D 7B9F
5.
A 29.000000
B 28.000000
C 27.000000
D 26.000000
6.
A 162E
B 172D
C 162F
D 172F
7.
A 01
B 00
C 10
D 00
8.
A 4 4 3
B 4 4 4
C 4 3 4
D 4 3 3
9.
A 21
10
0 1
B 21
10
10
C 21
10
00
D 21
10
1 1
10.
A 3
B 4
C 6
D 5
11.
A 2012
B 2018
C 2020
D 2024
12.
A 4
B 5
C 6
D 8
13.
B within while 2
C Infinite loop
D within while 3
14.
A After
B In for After
C Infinite loop
15.
A void fun(int p[ 4
{
}
B void fun(int *p 4
{
}
C void fun(int *p 4
{
}
D void fun(int *p 3 4
{
}
16.
A a
B a, d
C a, c
D c, d
17.
18.
19.
A d=10
C b=10
D d=%d
20.
A checkthecode
B edocehtkcehc
21.
A 1 8 9 9
B 2 2 10 10
C 1 1 9 9
D 1 8 10 10
22.
A 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
C 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
D 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
23.
24.
A hello 115
C good 100
D hello 110
25.
A a and b
B a
C b
D none of these
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
Q. 1 3
1
Q. 2 6
Q. 3 6