Patey

Untitled

Dec 16th, 2020
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n, i,x,s;
  6.     cout << "Dati numarul de elemnte: ";
  7.     cin >> n;
  8.     i = 1;
  9.     while (i <= n)
  10.     {
  11.         cout << "Dati un alt element: ";
  12.         cin >> x;
  13.         if (x % 2 == 1)
  14.         {
  15.             cout << "Ultima cifra a numarului este " << x % 10;
  16.             cout << "\n";
  17.         }
  18.         else {
  19.             s = 0;
  20.             while (x > 0)
  21.             {
  22.                 s = s + x % 10;
  23.                 x = x / 10;
  24.             }
  25.             cout << "Suma cifrelor este " << s;
  26.             cout << "\n";
  27.         }
  28.         i++;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment