In: Computer Science
who to write a program c++ that reads in an integer between 0 and 1000 and adds all the digits in the integer?
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter a number between 0 and 1000:
";
cin>>n;
int sum = 0;
while(n>0)
{
sum += n%10;
n = n/10;
}
cout<<"Sum of all the digits of a number is:
"<<sum;
}
//Code Snippet
//Output