Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Number Names

program numbernames;
//Jonas Yip
var
  aunit : array[1..9] of string = ('one','two','three','four','five','six','seven','eight','nine');
  tens : array[1..9] of string = ('ten','twenty','thirty','forty','fifthty','sixty','seventy','eighty','ninety');
  irregular : array[1..9] of  string = ('eleven','tweleve','thirteen','fourteen','fithteen','sixteen','seventeen','eighteen','nineteen');
  input : string;


function getUnit(nUnit : string) : string;
var
  unitDigit,error : integer;
  word : string;
begin
  val(nUnit,unitDigit,error);
  if (unitDigit <> 0) then
    word := aunit[unitDigit]
  else
    word := 'zero';
  getUnit := word;
end;

function getTenth(nTenth : string) : string;
var
  error,unitDigit,TenthDigit,number : integer;
  word : string;
begin
  val(nTenth,number,error);
  if (number>10) and (number <20) then
  begin
    val(nTenth[2],unitDigit,error);
    word := irregular[unitDigit];
  end
  else
    begin
      val(nTenth[1],TenthDigit,error);
      val(nTenth[2],unitDigit,error);
      word := tens[TenthDigit];
      if (unitDigit>0) then
        word := word + '-' + getUnit(nTenth[2]);
    end;
  getTenth := word;
end;
function getHundred(number : string) : string;
var
  error,hundrethDigit,uUnit,nTenth : integer;
  word,twoDigit : string;
begin
  if (number[2]='0') and (number[3]='0') then
    word := getUnit(number[1]) + ' hundred'
  else if (number[2]='0') then
    word := getUnit(number[1]) + ' hundred ' + getUnit(number[3])
  else
    begin
      twoDigit := number[2] + number[3];
      word := getUnit(number[1]) + ' hundred ' + getTenth(twoDigit);
    end;
  getHundred := word;
end;
function getThousand(number : string) : string;
begin
  getThousand := getUnit(number[1]) + ' thousand ' + getHundred(copy(number,2,3));
end;
function getTenThousand(number : string) : string;
var
  word : string;
begin
  if (number[3] = '0') and (number[4]='0') then
    word := getTenth(copy(number,1,2)) + ' thousand ' + getUnit(copy(number,5,1))
  else if (number[3] = '0') then
    word := getTenth(copy(number,1,2)) + ' thousand ' + getTenth(copy(number,4,2))
  else
    word := getTenth(copy(number,1,2)) + ' thousand ' + getHundred(copy(number,3,3));
  getTenThousand := word;
end;

function getHundredThousand(number : string) : string;
var
  word : string;
begin
  if (number[2] = '0') and (number[3] = '0') then
    word := getUnit(number[1]) + ' hundred ' + getHundred(copy(number,4,3))
  else if (number[2] = '0') then
    word := getUnit(number[1]) + ' hundred ' + getThousand(copy(number,3,4))
  else
    word := getUnit(number[1]) + ' hundred ' + getTenThousand(copy(number,2,5));
  getHundredThousand := word;
end;

function getMillion(number : string) : string;
var
  word : string;
begin
  word := getUnit(number[1]) + ' million ' + getHundredThousand(copy(number,2,6));
  getMillion := word;
end;
procedure numberName(numberStr : string);
var
  word : string;
  error,unitDigit,TenthDigit,number : integer;
begin
  case length(numberStr) of
    1 : word := getUnit(numberStr);
    2 : word := getTenth(numberStr);
    3 : word := getHundred(numberStr);
    4 : word := getThousand(numberStr);
    5 : word := getTenThousand(numberStr);
    6 : word := getHundredThousand(numberStr);
    7: word := getMillion(numberStr);
  end;
  writeln(word);
end;
procedure loop();
var
  count : integer;
  strNum : string;
begin
  for count := 1000000 to 9999999 do
  begin
    str(count,strNum);
    numberName(strNum);
  end;
end;
begin
  write('Enter number > ');
  readln(input);
  numberName(input);
  //loop();
  readln;

end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.