Answer to Question #229938 in C++ for Asku

Question #229938

Sum of digits

Input

12

Output

1+2=3


1
Expert's answer
2021-08-26T07:45:27-0400
#include<iostream>
#include<string>
using namespace std;
int sum(int number){
	int sum = 0.0;
	while(number != 0){
		sum = sum+ number % 10;
		number = number /10;
	}
	return sum;
}
//Testing code
int main(){


	cout<<sum(12)<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS