Showing posts with label ordinal numbers in pascal. Show all posts
Showing posts with label ordinal numbers in pascal. Show all posts

Tuesday, November 24, 2015

Ordinal Numbers Using Pascal

As I learned computer programming my first programming language that I have learned is Pascal my compiler that I am using during those days in college in Turbo Pascal 5.0. In this program I would like to reminisce the past by writing a program using Pascal as my programming language to accept a number from the user and then convert the number into ordinal equivalent values.

In this sample program I am using Turbo Pascal 5.5 that is widely available right now to download free from any charges over the Internet. This problem I encounter during my college day's in our programming class.  





Sample Program Output


Program Listing


(* Ordinal_Numbers.pas                       *)
(* Written By Mr. Jake R. Pomperada, MAED-IT *)
(* Tools : Turbo Pascal 5.5. For DOS         *)
(* Date  : November 24, 2015                 *)

Program Ordinal_Numbers;
Uses Crt;

Var number : integer;

  message  : string;
  a              : integer;
  mod100   : integer;
  mod10    : integer;

begin
   a:=0; mod10:=0; mod100:=0;

  clrscr;
  textcolor(yellow);
  write('Ordinal Number Generator in Pascal');
  writeln; writeln; writeln;
  write('Enter a Number : ');
  readln(number);
  writeln; writeln;
  for a:= 1 To number Do
   Begin
     mod10 := (a mod 10);
     mod100 := (a mod 100);

   if (mod10 = 1) AND (mod100 <> 11) then
     Begin
       message := 'st';
     End

   else if (mod10 = 2) AND (mod100 <> 12) then
     Begin
       message := 'nd';
     End

   else  if (mod10 = 1) AND (mod100 <> 11) then
     Begin
       message := 'rd';
     End
  else
    Begin
     message := 'th';
    End;

        write(' ',a,message,' ');
   End;

  writeln; writeln;
  write('End of Program');
  readln;
End.