[Pascal] Dizer o numero por extenso
Aqui esta um programa em pascal que escreve os numeros até 9999 em extenso, uma pequena brincadeira que demorou algum tempo a fazer nas aulas de BP:
program extenso;
uses crt;
var texto:string;
tamanho: integer;
begin
clrscr;
writeln ('..::]Programa produzido pelo cenourinha[::..');
writeln (' ..::]www.webtuga.com[::.. ');
readkey;
clrscr;
writeln(' Introduza um numero para passar a extenso ');
read(texto);
tamanho:=length(texto);
writeln('Milhares: ',texto[1]);
writeln('Centenas: ',texto[2]);
writeln('Dezenas: ',texto[3]);
writeln('Unidades: ',texto[4]);
readkey;
case texto[1] of
'1':write('Mil');
'2':write('Dois Mil');
'3':write('Tres Mil');
'4':write('Quatro Mil');
'5':write('Cinco Mil');
'6':write('Seis Mil');
'7':write('Sete Mil');
'8':write('Oito Mil');
'9':write('Nove Mil');
end;
if (texto[3]='0') and (texto[4]='0') then
write(' e Cem ')
else
case texto[2] of
'1':write(' Cento e');
'2':write(' Duzentos e');
'3':write(' Trezentos e');
'4':write(' Quatrocentos e');
'5':write(' Quinhentos e');
'6':write(' Seiscentos e');
'7':write(' Setecentos e');
'8':write(' Oitocentos e');
'9':write(' Novecentos e');
end;
if texto[3]='1' then
if texto[3]+texto[4]='11' then
write('onze');
if texto[3]+texto[4]='12' then
write('doze');
if texto[3]+texto[4]='13' then
write('treze');
if texto[3]+texto[4]='14' then
write('Catorze');
if texto[3]+texto[4]='15' then
write('Quinze');
if texto[3]+texto[4]='16' then
write('Dezasseis');
if texto[3]+texto[4]='17' then
write('dezasete');
if texto[3]+texto[4]='18' then
write('Dezoito');
if texto[3]+texto[4]='19' then
write('dezanove');
case texto[3] of
'1':write(' ');
'2':write(' Vinte e');
'3':write(' Trinta e');
'4':write(' Quarenta e');
'5':write(' Cinquenta e');
'6':write(' Secenta e');
'7':write(' Setenta e');
'8':write(' Oitenta e');
'9':write(' Noventa e');
end;
if texto[3]<>'1' then
case texto[4] of
'1':write(' um ');
'2':write(' dois ');
'3':write(' tres ');
'4':write(' quatro ');
'5':write(' cinco ');
'6':write(' seis ');
'7':write(' sete ');
'9':write(' Oito ');
end;
readkey;
end.
Espero que gostem desta brincadeira, alguma duvida é só dizer
fiquem bem