Dear Sir,

Could you tell me how can I do this question?

Write a program that will readin three numbers nd output a message indicating whether or not the numbers were entered in ascending numerical order. (Equal entries are regarded as being in order, e.g. 4 4 5 is OK).

Cheers,

Recommended Answers

All 4 Replies

First let's see the algorithm....
We need 3 variables for the 3 numbers,right?
We have to check the numbers one by one to see what is bigger or smaller...
And then,alert the user ....

Program orders;

{$APPTYPE CONSOLE}

Uses
  SysUtils;
Var a,b,c:Integer;
Begin
  Write('a: '); {1.number}
  ReadLn(a);
  Write('b: '); {2.number}
  ReadLn(b);
  Write('c: '); {3.number}
  ReadLn(c);
  {check the numbers}
  If (a <= b) And (a < c) And (b <= c) Then WriteLn('Good Order!')
  Else WriteLn('Wrong Order!');
  ReadLn;
End.
{Created by FlamingClaw 2009.06.06.}

Thank you for your help and I was misunderstanding the question in before. I thought it ask me to swap the numbers if they are not in ascending numerical order.

Cheers,

{
Thank you for your help and I was misunderstanding
the question in before. I thought it ask me to swap
the numbers if they are not in ascending numerical
order.
}


Program Fixed_orders;

{$APPTYPE CONSOLE}

Uses
  SysUtils;

Const minimum = 1;
      maximum = 3;

Var MyArray:Array[minimum..maximum]Of Integer;
    MyI,MyK,MyT:Integer;

Begin
  {get the 3 numbers from the user}
  For MyI:=minimum To maximum Do Begin
    Write(MyI,'. number is: ');
    ReadLn(MyArray[MyI]);
  End;

  {if needed exchange the order}
  For MyI:=minimum To maximum-1 Do Begin
    For MyK:=MyI+1 To maximum Do Begin
      If MyArray[MyK] < MyArray[MyI] Then Begin
        MyT:=MyArray[MyK];
        MyArray[MyK]:=MyArray[MyI];
        MyArray[MyI]:=MyT;
      End;
    End;
  End;

  WriteLn;
  WriteLn('The results are:');
  {write the results}
  For MyI:=minimum To maximum Do Write(MyArray[MyI],',');
  ReadLn;
End.
{Created by FlamingClaw 2009.06.06}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.