Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to make a pascal program for finding the largest of three numbers

+6 votes
asked Nov 22, 2019 by Omari Warner (260 points)

6 Answers

+4 votes
answered Feb 10, 2021 by root (810 points)
selected Feb 12, 2021 by Omari Warner
 
Best answer
function maximum(x, y: integer): integer;
  begin
    if y > x then
      begin
        x := y;
      end;
    maximum := x;
  end;

function maximum(x, y, z: integer): integer;
  begin
    x := maximum(x, y);
    x := maximum(x, z);
    maximum := x;
  end;
0 votes
answered Nov 24, 2019 by RAGE MONSTER rocks (570 points)
#include <stdio.h>

int main()
{
   int a,b,c,g=-32768;
   printf("enter 3 numbers  :  ");
   scanf("%d%d%d",&a,&b,&c);
   if(a>g)
     g=a;
   if(b>g)
     g=b;
   if(c>g)
     g=c;
     
   printf("greates of 3  :  %d",g);
   return 0;
}
commented Nov 24, 2019 by Andrej (100 points)
well, that is not pascal ...
0 votes
answered Feb 11, 2021 by Omari Warner (260 points)
program largest;
uses crt;
var
max : real;
a,b,c:real;

begin
ClrScr;
max:=0;
writeln('Enter first number');
readln(a);
writeln('Enter second number');
readln(b);
writeln('Enter third number');
readln(c);
   if (a>max) Then
     max:=a;
   if(b>max) Then
     max:=b;
   if(c>max)Then
     max:=c;
   writeln('greates of 3 numbers is :  ',max:2:2);
writeln('Enter any number to continue');
readln();
end.
commented Feb 11, 2021 by Peter Minarik (86,580 points)
I'm pretty sure your solution doesn't work for negative numbers.

I'd just set `max := a` every time, and get rid of the condition for comparing `a` to `max`.
0 votes
answered Feb 11, 2021 by Jeff The Chicken (2,920 points)
Whatever program you are using, all you need is three input variables. then a fourth variable that becomes the same as one of the variables only if larger then them. Compare the variable with all three in this way, and it will end up becoming the largest of the three. Then, print it.
0 votes
answered Mar 9, 2021 by Graham Pearl (140 points)

The concept is to use either a series of inputs and store the largest based on the conditional from a loop, or to use a recursive method to resolve the challenge.

program Hello;
var  input : Integer;
      maxX : Integer;
begin
 maxX := -1;
 REPEAT
  write ('Enter a value (or -1 to exit) : ');
  Readln(input);
  if (input > maxX) then maxX := input;
 UNTIL (input = -1) 
  WriteLn(maxX);
end.

The above will solve for all positive values, the maxX is storing the largest value until the exit flag is entered. Adjust the exit flag (-1) to an alternative flag value if needed. 

There are additional approaches, this is however the simplest.

0 votes
answered Aug 28, 2021 by abd11a (260 points)

https://onlinegdb.com/BeAzxy8NF

var max,x,y,z:integer;
begin
    x:= 112;
    y:= 22;
    z:= 36;
    
    max := x;
    
    if max < y then max :=y;
    if max < z then max :=z;
    
    writeln (max);

end.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...