assalamualaikum,
morning,
lab task week 10,
finding the factorial
[THIS IS USING PASCAL CODING ONLY]
the program should be like this....
- if we put number between 1..7, it will multiply all the number between 1 until that number,
eg:
1! = 1x1
2! = 1x2
3! = 1x2x3 and so on
2. if the number is negative or more than 7, it will display, 'wrong input'
3. if the number is 0, then the value of factorial is 1
so, the key words is using the for..do loop and also the if..then..else...
the coding...
******************************************************
program
factorial ;
var
i,num,total:integer;
begin
writeln('insert number between 0..7');
readln(num);
total:=1 ;
if (num>0) and (num<=7)then
begin
for i:= 1 to num do
total:= total*i ;
writeln(num,'!>> ',total);
end
else if (num=0) then
writeln('0!= 1')
else
writeln('wrong input');
readln;
end.
******************************************************
all the bestt!!!
~END OF THE DAY: happy fasting deyy all muslims!
No comments:
Post a Comment