Write a function in C++ to calculate the sum of digits of an integral number
Answers
Answered by
2
#include <iostream.h>
using namespace std;
// function declaration
int sumcalc(int num);
cout << "Enter a number : ";
cin >> num;
sum = sumcalc(num);
cout << “ sum of digits is : “<< sum<<endl;
return 0;
}
//function to calculate sum
int max(int num) {
int n, sum = 0;
n= sum;
while(n!=0){
sum = sum + n%10;
n = n/10;
}return sum;
}
Similar questions
Biology,
7 months ago
Hindi,
7 months ago
Science,
1 year ago
History,
1 year ago
Political Science,
1 year ago