Answer to Question #236790 in C++ for john

Question #236790

Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14.


1
Expert's answer
2021-09-14T00:41:48-0400
#include<iostream>
using namespace std;
int main() 
{ int number,x;
cout<<"Enter an interger between 0 and 1000: ";
cin>>number;
  int A = number % 10; 
  int B = (number % 100) / 10; 
  int C = number / 100; 
  x=A + B + C;
  cout<<x;
   
} 

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