1) Escrever um programa que leia um número inteiro qualquer de 4 dígitos. Em seguida efetue o seguinte cálculo:
d1 + d2 - d3 * d4 e a seguir imprima o resultado.
Exemplo: Suponha o número 2413
2 + 4 - 1 * 3
Lista de comentários
ribass
========================= *** Em Clipper cls Do While .t. d1:=d2:=d3:=d4:=0 @ 10,12 get d1 picture [9] @ 10,13 get d2 picture [9] @ 10,14 get d3 picture [9] @ 10,15 get d4 picture [9] read if lastkey()=27 quit end @ 10,17 say [ => ]+Str(d1+d2-d3*d4,4) enddo;
================================== **ou Delphi.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Label1: TLabel; procedure Edit1Change(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject); var d1,d2,d3,d4: Integer; begin d1:=0; d2:=0; d3:=0; d4:=0; if Length(Edit1.Text)>=1 then d1:=strtoint(copy(Edit1.Text,1,1)); if Length(Edit1.Text)>=2 then d2:=strtoint(copy(Edit1.Text,2,1)); if Length(Edit1.Text)>=3 then d3:=strtoint(copy(Edit1.Text,3,1)); if Length(Edit1.Text)=4 then d4:=strtoint(copy(Edit1.Text,4,1)); Label1.Caption:=IntToStr(d1+d2-d3*d4);end; end.
Lista de comentários
*** Em Clipper
cls
Do While .t.
d1:=d2:=d3:=d4:=0
@ 10,12 get d1 picture [9]
@ 10,13 get d2 picture [9]
@ 10,14 get d3 picture [9]
@ 10,15 get d4 picture [9]
read
if lastkey()=27
quit
end
@ 10,17 say [ => ]+Str(d1+d2-d3*d4,4)
enddo;
==================================
**ou Delphi.
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Edit1: TEdit; Label1: TLabel; procedure Edit1Change(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject);
var d1,d2,d3,d4: Integer;
begin
d1:=0; d2:=0; d3:=0; d4:=0;
if Length(Edit1.Text)>=1 then
d1:=strtoint(copy(Edit1.Text,1,1));
if Length(Edit1.Text)>=2 then
d2:=strtoint(copy(Edit1.Text,2,1));
if Length(Edit1.Text)>=3 then
d3:=strtoint(copy(Edit1.Text,3,1));
if Length(Edit1.Text)=4 then
d4:=strtoint(copy(Edit1.Text,4,1));
Label1.Caption:=IntToStr(d1+d2-d3*d4);end;
end.