41.0k views
5 votes
Write a c++ program that reads the contents of a file containing integer numbers, then for

each number calculate the sum of its digits and print it on the screen.

1 Answer

0 votes

The sum of digits C++ program is written below

Step-by-step explanation:

#include <iostream>

using namespace std;

int main()

{

int number,sum=0,temp;

cout<<"Enter a number: ";

cin>>number;

while(number>0)

{

temp=number%10;

sum=sum+temp;

number=number/10;

}

cout<<"Sum of the given digit is= "<<sum<<endl;

return 0;

}

User Kyesha
by
5.9k points