0% found this document useful (0 votes)
2 views2 pages

Tutorial 1

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)
2 views2 pages

Tutorial 1

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

National Institute of Technology Silchar

Department of Computer Science and Engineering


CS221 - Programming and Data Structures
Tutorial 1

Last date for submission: 11-February-2026

1. Identify the output of the following. If any error report the same

Input Output
printf(”%d %d %d”, 32767, 32767+1, 32767+10); 32767 -32768 -32759
printf(”%ld %ld %ld”, 32767L, 32767+1L, 32767+10L); 32767 32768 32777
printf(”%o %x”, 32767, 32767); 77777 7fff
printf(”%d”,‘a’); 97
printf(”%c”, 100); d
Value of x ? x = 6.0/7.0 0.857143
Value of y ? y = 6 / 7 0
Value of x ? x = 9-12/3+3*2-1 10
Value of A ? A = (int)7.5 7
Value of r ? r = (float) 10/3; 3.333333
Value of m ? m = n++ -j+10; where n=2, j=-1 13
Value of x,y,z ? x=y=z=0.5=2.0=-5.75; Error
Value of m ? m = ++a * 5; where a = -2; -5
scanf(“%d %s”, &no, name); Input : 1 New Delhi 1 New
scanf(“%d %15s”, &no, name); printf(“%d %15s”, &no, name); Input : 12 New
12 New Delhi
scanf(“%d %[a-z]s”, &no, name); printf(“%d %15s”, &no, name); Input 12 NewDelhi
: 12 NewDelhi 788010
scanf(“%2d %5d”, &n1,&n2); printf(“%d %d”, n1,n2); Input : 38672 12 38 672
y = 98.7654; printf(”%7.4f”,y); 98.7654
y = 98.7654; printf(”%11.4e”,-y); -9.8765e+01
y = 98.7654 printf(”%e”,y); 9.876540e+01
printf(“%d %4.2f”, 1234, 456); 1234 0.00
scanf(“%c %d”, &year, &code); Input:1988 x 1 988

2. Rewrite the following expression using a conditional operator



4x + 100,
 for x < 40
s = 300, for x = 40

4.5x + 150, for x > 40

Answer : s=(x=40)?300:(x<40)?4x+100:4.5x+150;

3. Identify the output of the following segments. If any error report the same

(a) if (x+y =z && y > 0) printf(“ ”); Answer : Error

1
(b) if (x > 1);
a = 2+3;
else
a = 0; Answer : else without if statement
(c) Assume x=5, y=0, z=1
if (x == 0 || x && y)
if (!y)
z =0;
else
y = 1; Answer : x=5, y=0, z=1
(d) Assume x=2, y=1, z=0;
switch(x)
{
case 2:
x = 1;
y = x+1;
case 1:
x=0;
break;
default:
x=1;
y=0;
}
Answer : 0 2 0
(e) Simplify the compound expression
!(x ≤ 5) && (y==10) && (z<5)

Answer : (x >5) && (y==10) && (z<5)

You might also like