Write a C++ program and flowchart to calculate sum of digits of a number.
Expert's answer
#include<iostream>
using namespace std;
intsum(intnumber){
intsum = 0.0;
while(number!= 0){sum = sum+ number % 10;
number = number /10;
}
returnsum;
}
//Testing code
int main(){
int n;
cout<<"Enter int N: ";
cin>>n;
cout<<sum(n)<<endl;
}
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot