Week 1 Solution PDF
Week 1 Solution PDF
Quiz1Solutions
Forquestions,refertotheQuizpage.Onlythesolutionsaregivenbelow
1. Answer:C
x++incrementsthevalueto11.Soprintfstatementusesx=11.
2. Answer:A
TheASCIIvalueofais97whichgetsswitchedwhileswitchingthecharc.
3. Answer:C
Theexpressionb*c+dagetsevaluatedfirst,whichthensetsthevalueofato9.Thisvalue
isusedforincrementingx.
4. Answer:B
intb=1.1assigns1tob.Comparinga==b,compares1with1.1whichisFALSE.
5. 11
Thesemicolonaftertheforloopterminatesitandthebracketsaretreatedasasingleblock,
thusx++isexecutedonlyonce.
6. 13
Conditionisevaluatedtotrueforanynonzerovalue.So,thefirstandlastIFconditionsare
evaluatedasTRUE.
7. Answer:C
Thedoloopexecutesonceandgoestothecheck.Inthecheck,thereisonemore
increment.Sothefinalansweris12.
8. Answer:C
Rightshift4timesof22is22/(2*2*2*2)=1(integerdivision)
9. Answer:A
,canalsobeusedasanoperatorandithastheleastprecedence.Sointhefirststatement
assignmentisdonefirst.Inthesecond,assignmentisdonelater.
10. Answer:C
printfreturnsnumberofcharactersprinted.Sothefirst10canbeprintedusingprintfinthe
condition.Sincethestatementprintsmorethan0characters,theIFconditionistrueand
hencetheIFpartwillprintonemore10.
11. 9
=5%(55/2)
(53)+5
=5%(52)
(53)+5
=5%3
2+5
=2
2+5
=9
12. Answer:C
b=c=>b='A'
c=b=>c='A'
a=c=>a='A'
c=a=>c='A'
ProgrammingQuestion#1
#include<stdio.h>
intmain(){
intx,y,i,a
intcount=0,flag=0
scanf("%d%d",&x,&y)
for(i=xi<=yi++){
for(a=0a<=ia++)
{
if(i==a*a)
{
flag=1
}
}
if(flag==1)
count++
flag=0
}
printf("%d",count)
return1
}
ProgrammingQuestion#2
#include<stdio.h>
intmain(){
intx,i,sum=0
scanf("%d",&x)
for(i=1i<xi++){
if(x%i==0){
sum+=i
}
}
if(sum==x){
printf("yes")
}else{
printf("no")
}
return1
}
ProgrammingQuestion#3
#include<stdio.h>
intmain()
{
intnum
intproduct=1,i,j
scanf("%d",&num)
while(num){
product*=num%10
num=num/10
}
printf("%d",product)
return0
}
ProgrammingQuestion#4
#include<stdio.h>
intmain()
{
intx1,y1,x2,y2,x3,y3
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3)
if((y2y1)*(x3x1)==(y3y1)*(x2x1))
printf("%s","Yes")
else
printf("%s","No")
}