Adding Digits

Description:

Write a C++ Program to Add Digits of Number using pointer. Test Case 1 Input (stdin) 23 Expected Output The sum of the digits of 23 is 5 Test Case 2 Input (stdin) 6474 Expected Output The sum of the digits of 6474 is 21

Program :

#include<iostream>

using namespace std;

int main()

{

int num, rem=0, sum=0;

//cout<<"Enter a Number :";

cin>>num;

int temp=num;

while(num>0)

{

rem=num%10;

sum=sum+rem;

num=num/10;

}

cout<<"The sum of the digits of "<<temp<<" is "<<sum;

  return 0;}