👤
a fost răspuns

Se citeste un sir cu n numere naturale si se cere sa se tipareasca suma cifrelor fiecarui element! 
Va rog rezolvare in c++!
Dau funda!


Răspuns :

#include <iostream>

using namespace std;

int main() {

int n, element, s=0, cifra;

cout << "Introduceti n : ";

cin >> n;

for (int i = 1; i <= n; i++) {

 cout << "\nIntroduceti urmatorul element : ";

 cin >> element;

 

 s = 0;

 

 while (element > 0) {

  cifra = element % 10;

  s = s + cifra;

  element = element / 10;

 }

 cout << "\nSuma cifrelor acestui element este " << s << endl;

 s = 0;

}

return 0;

}