(Sum of digits) Make a program that reads a three-digit integer from the file "number.in" and then calculates sum of the digits and writes the result into the file"sum.out".Use the format of the sample output in the file "sumout".
1
Expert's answer
2013-02-05T10:59:52-0500
#include<iostream> #include <fstream> using namespace std;
int main() { ifstream in("sum.in"); ofstream out("sum.out"); int a,c=0; in >> a; while (a>0) { c+=a; a/=10; } out << c; return 0; }
Comments
Leave a comment