Given an integer N (> 0). Using the operation of dividing the target and taking the remainder of the division, find the number obtained by reading the number N from right to left.


#inсlude <vcl.h> #include <iostream.h> #include <conio.h> void main() { int n, s, k, l; cout << " vvedite n: "; cin >> n; while (n > 0) { if (k = n % 10) s = s + kn = n / 10; } cout << " symma= "; cin >> s; cout << " kolishestvo= "; cin >> l; getch(); } 

How to write the correct condition, please help.

    1 answer 1

    You just need to select the decimal digits on the right and build a number from them.

    if not needed

     s = 0; while (n) { s = s*10+n%10; n /= 10; } cout << "summa = "<<s<<"\n"; 

    summa, this is of course a strange name for an answer. palindrome better reflects the essence of the task.

    What is not clear, ask

    • the program still does not work, gives an error - IvAn
    • one
      @IvAn, specify what the error gives. looking at your code, it’s not surprising that you have a trite ";" between operations is not worth it. The example you were given should work. - margosh
    • Now I understood everything - IvAn
    • @IvAn, but in this case, do not want to accept the answer? This is done by clicking on the daw;) - margosh