DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Pascal and Delphi (http://www.daniweb.com/forums/forum124.html)
-   -   Could you tell me how can I do this question? (http://www.daniweb.com/forums/thread201908.html)

turbomen Jul 6th, 2009 5:39 am
Could you tell me how can I do this question?
 
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,

FlamingClaw Jul 6th, 2009 6:14 am
Re: Could you tell me how can I do this question?
 
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 ....

FlamingClaw Jul 6th, 2009 6:38 am
Re: Could you tell me how can I do this question?
 
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.}

turbomen Jul 6th, 2009 7:21 am
Re: Could you tell me how can I do this question?
 
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,

FlamingClaw Jul 6th, 2009 9:10 am
Re: Could you tell me how can I do this question?
 
{
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}


All times are GMT -4. The time now is 1:04 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC