adspace


solve the problem in the programming language C++"if a five
digit number is input through the keyboard.Write a program
to calculate the sum of its digits(hint: use the modulus
operator)

Answer Posted / Jyoti Chandra Srivastava

Here's a simple C++ code snippet that calculates the sum of digits in a five-digit number using the modulus operator:

```cpp
#include <iostream>
using namespace std;

int main() {
int num, sum = 0;

cout << "Enter a five-digit number: ";
cin >> num;

// Extract digits and calculate their sum
for(int i = 10000; i > 0; i /= 10) {
sum += (num / i) % 10;
}

cout << "Sum of its digits: " << sum << endl;

return 0;
}
```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++

1271