Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
438 B
3
Indexable
Never
#include <iostream>
using namespace std;

int main() {
    int n, suma = 0;

    cout << "Introduceti un numar de maxim 4 cifre: ";
    cin >> n;

    if (n < 0 || n > 9999) {
        cout << "Numarul introdus trebuie sa fie intre 0 si 9999.";
        return 0;
    }

    while (n > 0) {
        suma += n % 10;
        n /= 10;
    }

    cout << "Suma cifrelor numarului introdus este: " << suma;

    return 0;
}