You are on page 1of 3

Example 1

Program Product:
Read a , b;
c=a*b;
Print c;
end;

Example 2
Program checknumber:
Read num;
if num is not 5 or 6
print number is not a 5 or 6;
endif;
end;

Example 3
Program numbercolor:
Read num;
if num>=0 and num<=10
print "red";
if num>=10 and num<=20
print "blue";
if num>=20 and num<=30
print "green";
else
print "it is not a correct color option"
endif;
end;

Example 4
Program multiples_of_five:
i=5;
while(i<=100)
do print i;
i=i+5;
end while;
end;

Example 5
Program evencount:
//asuming counting is starting from 0
i=0;
count=0;
Read num;
while(i<=num)
do i=i+2;
count=count+1;
endwhile;
print count;
end;

//alternate way
Program evencount:
i=0;
Read num;
count = floor of num/2 +1;
print count;
end;
Example 6
Program average_min_max:
Read num1,num2,num3,num4,num5;
average = (num1+num2+num3+num4+num5)/5;
If(num1 < num2)
max = num2;
Else
max = num1;
endIf;
If(num3 > max)
max = num3;
endIf;
If(num4 > max)
max = num4;
endIf;
If(num5 > max)
then max = num5;
endIf;
print "The max is" max;
If(num1 > num2)
then min = num2;
Else
then min = num1;
endIf;
If(num3 < min)
then min = num3;
endIf;
If(num4 < min)
then min = num4;
endIf;
If(num5 < min)
then min = num5;
endIf;
print "The min is" min;
end;

HomeWork1
Program Sortedthreenumbers:
Read num1, num2, num3
If (num1 < num2)
If(num2 < num3)
then print num1 , num2, num3
Else
If(num3 < num1)
then print num3, num1, num2
Else
print num1, num3, num2
else
If(num1 < num3)
then print num2 , num1, num3
Else
If(num3 < num2)
then print num3, num2, num1
Else
then print num2, num3, num1

HomeWork2
Program sumuntillstop:
Read num;
sum = 0;
While(num >= 0)
do sum = num + sum;
Read num;
end While;
print sum
end;

You might also like