Pseudocode Practice Questions-Ans
Pseudocode Practice Questions-Ans
2. count=500
largest=0
smallest=999
totalFS=0
While count<>0 do
Input time
count=count-1
finalspeed=200/time
if finalspeed>largest then largest=finalspeed
if finalspeed<smallest then smallest=finalspeed
totalFS=totalFS+finalspeed
print finalspeed
endwhile
print largest, smallest
average=totalFS/500
print average
3. count=1000
totalhts=0
totalwts=0
while count<>0 do
input ht, wt
if ht>2 and ht<0 then print “error in height”
else if wt>130 and wt<0 then print “error in weight”
else
count=count-1
totalhts=totalhts+ht
totalwts=totalwts+wt
endif
endif
endwhile
avght=totalhts/1000
avgwt=totalwts/1000
print avght, avgwt
4. Total=0
largest=0
Input number
Count=0
While number<>-1 do
Total=Total+number
If number>largest then largest=number
Input number
Count=Count+1
Endwhile
Average=Total/Count
Print average, largest
5. Count=3650
Total=0
best=0
worst=999
Occasions=0
While count<>0 do
Input exchangerate
Count=Count-1
Total=Total+exchangerate
If exchangerate>best then best=exchangerate
If exchangerate<worst then worst=exchangerate
If exchangerate>2 then Occasions=Occasions+1
Endwhile
Average=Total/3650
Print Average, best, worst, Occasions
CW
6. lessTh=0
moreTh=0
Input number
While number<>-1 do
If number<1000 then lessTh=lessTh+1
If number>1000 then moreTh=moreTh+1
Input number
Endwhile
Print lessTh, moreTh
7. Count=365
Cloudy=0
Raining=0
Sunny=0
Foggy=0
Highest=0
Lowest=999
While count<>0 do
Input weathertype, temp
Count=Count-1
If weathertype=”Cloudy” then Cloudy=Cloudy+1
Else If weathertype=”Raining” then Raining=Raining+1
Else If weathertype=”Sunny” then Sunny=Sunny+1
Else If weathertype=”Foggy” then Foggy=Foggy+1
If temp>Highest then Highest=temp
If temp<Lowest then Lowest=temp
Endwhile
Print Cloudy, Raining, Sunny, Foggy, Highest, Lowest
8. Count=1000
Whole=0
While Count<>0 Do
Input number
Count=Count-1
Y=INT(number)
If number=Y then Whole=Whole+1
Endwhile
Print Whole
9. Input number
Count=0
Divnum=number
While Divnum<>0 Do
Divnum=Divnum/10
Count=count+1
Endwhile
Print Count, number
10. Count=50
Palcnt=0
While Count<>0 Do
Input D1, D2, D3, D4
Count=Count-1
If D1=D4 AND D2=D3 then Palcnt=Palcnt+1
Endwhile
PercentagePal=Palcnt*2
Print PercentagePal