Draw a flowchart to find the largest of three numbers x, y and z.
Write a Pascal Program to find the largest of three numbers x, y and z.
Method I
program FindMaxFrom3; var x,y,z,max :integer; begin writeln('Enter a Number?'); read(x); writeln('Enter a Number?'); read(y); writeln('Enter a Number?'); read(z); if (x > y) then if (z > x) then max:=z else max:=x else if (z > y) then max:=z else max:=y; writeln('Maximum number is :'); write(max); readln; end.
Method II
program FindMaxOf3num; var x,y,z,max :integer; begin writeln('Enter a Number?'); read(x); writeln('Enter a Number?'); read(y); writeln('Enter a Number?'); read(z); if (x > y) then max:=x else max:=y; if (z >max) then max:=z; writeln('Maximum number is :'); write(max); readln; readln; end.
or
We can use a Pascal procedure to find the maximum number of given three numbers as input parameters and maximum number as output parameter . Below Pascal program shows that
program findMaximum; var m:integer; procedure findMax(x, y, z: integer; var max: integer) ; begin if (x > y) then max := x else max := y; if (z > max) then max := z; end; begin findMax(20,300,120,m); writeln(m); readln; end.
or
We can use a Pascal function to find maximum number from given three numbers by passing three numbers as input parameters and return the maximum number as return value. Below Pascal program shows that
program findMaximumFunction; var m:integer; function findMax(x, y, z: integer):integer ; var max:integer; begin if (x > y) then max := x else max := y; if (z > max) then max := z; findMax:=max; end; begin m:=findMax(20,300,120); writeln(m); readln; end.
No comments:
Post a Comment