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.
#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;
}
Comments
Leave a comment