E Balagurusamy CH 5 Solution 2.
E Balagurusamy CH 5 Solution 2.
***********
ANSI C REVIEW QUESTION SOLUTION
Chapter- 05
Page 48
Ans: if...else.
(e)The expression !(xl=y)can be replaced by the expression...
Ans: x==y.
if(n>0)
X=X*1;
y=y-1;
printf(%d %d", x.y): 1and
What will be the values of x and y if n assumes a value of (a)
(b) 0.
Solution:
(a)2,0
(b) 1,0
Answer:
if (grade<=59) STEVE JOBS
if(grade >=50)
Second=second+1;
Answer
if (number>100)
Printf("Out of range");
else if (number<0)
Printf('Out of range");
else
Sum=sum+1;
if (M1>60)
if (M2 >60)
Printf("AdmittedIn");
else if (T>200)
Printf" AdmittedIn);
else if (T>200)
Printf("'Admitted In);
else
Printf("Not admittedin);
5.6:Assuming x=10 ,state whether the following logical expressions
are true or false:
(a)x==10 && x>10 && Ix Ans:False.
(b)x==10|| x> 10 && Ix Ans:True.
(c)x==10 && x>10||!lx Ans:False. STEVE JOBS
(d)x==10 ||x>10 || !x Ans:True.
(c)switch(x+y)
Answer: No erro.
(c(x**y==z)8&!(z>5)
Answer: !(x+y==z) || (z>5) x+y!=z || z>5
(d)(x<=5}&&(y==10)8&(z<5))
Answer: x>5|| y!=10 | z>=5
be their valuees
5.9:Assuming that x=5, y=0,and z=1 initially ,what will
after executing the following code segments?
(a jif(x && y)
x=10;
else
y=10;
Output: x= 5, y= 10,z= 1
(bif(xl|l y ||2)
10 STEVE JOBS
else
z=0;
Output: x5, y= 10, z=1
(c)if(x)
if(y)
10:
else
z=0;
Output: x= 5, y=0, z=0
5.10:Assuming that x=2,.y=1 and z=0 initially ,what will be their values
after executing the following code segments?
(a)
switchx)
case 2:
x=1;
y=x+1;
case 1:
x=0;
break;
default:
x=1;
y=0;
(b)
switch(y)
case 0: STEVE JOBS
x=0;
y=0;
case 2:
x=2;
z-2;
default:
x=1;
y-2;
Output: x=1,y= 2, z= 0
int m=1;
if( m==1)
printf ("Delhi");
if(m==2) Be careful- if there is
printf("Chennai"); semicolon (:) after else, it
else takes as a blank statement. So
printf("Banglore"); here printf¢END"); 'statement
else is not working with 'else.
Printf("END");
getch():
Output: Delhi Banglore END
Page 54
Output: 0 0 2
switch(ch)
case 'a':
printf("A"):
case 'b':
printf("B");
case 'c': STEVE JOBS
printf("C"):
Output: ABC
int x=10,y=20;
if(( x<y)|l (x*5)>10)
printf(%d",x);
else
printf("%d",y);
getch(:
Output: 10
main()
int a=10, b=5;
if(a>b)
if(b>5)
printf(%d",b);
else
printf(%d",a);
getch();
Answer: blank.
That means there will be no output.
STEVE JOBS
DFSIGAER D N[W WORLD
*********** ********