Advertisement
ADEPT_VANEYVA

Sort 3 number in up order

Jan 19th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.85 KB | None | 0 0
  1. {This program sorting 3 numbers in ascending order}
  2.  
  3. program sort;
  4.  
  5. uses crt;
  6. var
  7.   a, b, c, x: real;
  8.  
  9. begin
  10.   clrscr;
  11.   write('Enter a,b,c: ');
  12.   readln(a, b, c);
  13.   if a > b
  14.     then
  15.     if b > c then         { A max, C min }
  16.     begin
  17.       x := a;
  18.       a := c;
  19.       c := x;
  20.     end            
  21.      else
  22.     if c < a then         { A max, B min }
  23.     begin
  24.       x := a;
  25.       a := b;
  26.       b := c;
  27.       c := x;
  28.     end  
  29.     else                  { C max, B min }
  30.     begin
  31.       x := b;
  32.       b := a;
  33.       a := x;
  34.     end        
  35.   else
  36.   if c < a then           { B max,  C min }
  37.   begin
  38.     x := b;
  39.     b := a;
  40.     a := c;
  41.     c := x;
  42.   end      
  43.      else
  44.   if c < b then           { B max,  A min }
  45.   begin
  46.     x := b;
  47.     b := c;
  48.     c := x;
  49.   end;        
  50.   writeln(a:1:2, ',', b:1:2, ',', c:1:2);
  51. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement