Pascal: var n,a,s:longint; begin repeat write ('N = '); readln(n); until n in [10..99]; write ('A = '); readln(a); s:=0; while n<>0 do begin s:=s+n mod 10; n:=n div 10; end; if s>a then writeln ('YES') else writeln ('NO'); readln; end.
C++: #include <iostream> using namespace std;
int main() { int a,n,s = 0; do { cout <<"N = "; cin >>n; } while (n<10 || n>99); cout <<"A = "; cin >>a; while (n!=0) { s+=n%10; n/=10; } if (s>a) cout <<"YES" <<endl; else cout <<"NO" <<endl; return 0; }
Сначала сделал с рекурсивной функции, но затруднение было только с суммой элементов, по этому написал через цикл как впрочем и должно быть.
Console.WriteLine("Введите число");
int x = Convert.ToInt32(Console.ReadLine());
int y = x;
int sum = 0;
for (int i = 0; i < 4; i++)
{
y = x % 10;
x = x / 10;
Console.Write(y);
sum = sum + y;
}
Console.Write(" = " + sum);
Console.ReadLine();