Pagini recente » Cod sursa (job #1895156) | Cod sursa (job #813884) | Cod sursa (job #1908978) | Cod sursa (job #2784072) | Cod sursa (job #487516)
Cod sursa(job #487516)
{
Determinati ultima cifra a sumei:
S = 1^1 + 2^2 + 3^3 + ... + n^n
n<=500
}
program ultimaCifra;
var
pc:byte; {penultima cifra a numarului}
uc:byte; {ultima cifra a numarului}
rez:byte;
f:text;
procedure citeste;
begin
assign(f,'cifra.in');
reset(f);
pc:=0;
read(f,uc);
while not(eoln(f)) do
begin
pc := uc;
read(f,uc);
end;
close(f);
end;
procedure afiseaza;
begin
assign(f,'cifra.out');
rewrite(f);
write(f, rez);
close(f);
end;
function fx(n:integer):integer;
begin
case n of
0: fx:=0;
1: fx:=1;
2: fx:=5 + (((pc mod 2) * 2) mod 2) * 2;
3: fx:=2;
4: fx:=8;
5: fx:=3;
6: fx:=9;
7: fx:=2;
8: fx:=0;
9: fx:=9;
end;
end;
begin
citeste;
rez:=(3 * pc + (pc mod 2) * 2 + fx(uc)) mod 10;
afiseaza;
end.