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)



solve the problem in the programming language C++"if a five digit number is input through the..

Answer / 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

More C++ Code Interview Questions

a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.. ""EXAMPLE"" enter how many numbers to be inputted: 5 12 14 11 09 30 what number to search: 11 11 IS FOUND IN LOCATION 3 PLZZZ.. ELP ME...

3 Answers  


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

1 Answers   Nagarro,


Write a &#61521;(n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

1 Answers  


how to diplay a external image of output on winxp by using c & c++,

1 Answers  


How can I Draw an ellipse in 3d space and color it by using graph3d?

1 Answers  


output for printf("printf");

1 Answers  


Faster Computers Suppose you have a computer that requires 1 minute to solve problem instances of size 1000. What instance sizes can be run in 1 minute if you buy a new computer that runs 1000 times faster than the old one, assuming the following time complexities T(n) for our algorithm? (a) T(n) = O(n). (b) T(n) = O(n3). (c) T(n) = O(10n).

1 Answers   Qatar University,


program to find the magic square using array

1 Answers  


Write a simple encryption program using string function which apply the substitution method.

1 Answers  


Show by induction that 2n > n2, for all n > 4.

2 Answers   Karvy, Qatar University,


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

1 Answers  


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

1 Answers   HCL,


Categories