Программа считает сумму последних трех цифр: Pascal: var n:longint; sum,i:integer; begin repeat write ('N = '); readln (n): until (n>=10000) and (n<=99999); sum:=0; for i:=1 to 3 do begin sum:=sum+(n mod 10); n:=n div 10; end; writeln ('Summa: ',sum); end.
C++: #include <iostream> using namespace std; int main() { int n,sum = 0; do { cout <<"N = "; cin >>n; } while (n<10000 || n>99999); for (int I = 1; I<=3; I++) { sum+=n%10; n/=10; } cout <<"Summa: " <<sum <<endl; return 0; }
Pascal:
var n:longint;
sum,i:integer;
begin
repeat
write ('N = ');
readln (n):
until (n>=10000) and (n<=99999);
sum:=0;
for i:=1 to 3 do
begin
sum:=sum+(n mod 10);
n:=n div 10;
end;
writeln ('Summa: ',sum);
end.
C++:
#include <iostream>
using namespace std;
int main()
{
int n,sum = 0;
do
{
cout <<"N = ";
cin >>n;
}
while (n<10000 || n>99999);
for (int I = 1; I<=3; I++)
{
sum+=n%10;
n/=10;
}
cout <<"Summa: " <<sum <<endl;
return 0;
}