➽ Program:-

#include<iostream>

using namespace std;

int main()

{         

    long num, digit, sum = 0, temp;

    cout << "Enter the Number: ";

    cin >> num;

    temp = num;

 

    while(num > 0)

    {

        digit = num % 10;

        sum  = sum + digit;

        num /= 10;

    }

 

    cout << "Sum of the Digits of " << temp << " = " << sum;

    return 0;

}

➽ Output:-

Enter the Number: 456789
Sum of the Digits of 456789 = 39