You are on page 1of 1

// Loops

// Chapter 4 : CFE
//

#include <iostream>

using namespace std;

int sumDigits()
{
int x = 1234;
int n = x;
int sum = 0;
int rem = 0;

cout << "Enter an integer: ";


cin >> x;
n = x;

while(n)
{
rem = n % 10;
sum += rem;
n = n / 10;
}

cout << "Sum of digits of " << x << ": " << sum << endl;
return sum;
}

int main()
{
int count=0;
while(count < 5)
{
sumDigits();
++count;
}

return 0;
}

Question:
Have a look at the sample run.
What is the reason of the wrong answer when 11111111111 is entered?

You might also like