Question

In: Computer Science

IN C++ LANGUAGE PLEASE::::: All Hail Modulus Agustu!  The modulus operator is used all the time.  Realize that...

IN C++ LANGUAGE PLEASE:::::

All Hail Modulus Agustu!  The modulus operator is used all the time.  Realize that if you “mod” any number by a number “n”, you’ll get back a number between 0 and n-1.  For example, “modding” any number by 20 will always give you a number between 0-19.  Your job is to design (pseudocode) and implement (source code)a program to sum the total of all digits in an input integer number between 0 and 1000, inclusive. Notice that you need to extract individual digits from the input number using the remainder (modulus) and division mathematical operators. For example, if the input number is 123, the sum of its digits is 6.

Solutions

Expert Solution

pseudocode

Input a Number between 0 and 1000 inclusive
Initialize Sum to zero
While Number is not zero
Get Remainder by Number Mod 10
Add Remainder to Sum
Divide Number by 10
Print sum

code

#include<iostream>

using namespace std;
int getSum(int n)
{
int sum;
  
/* Single line that calculates sum */
for (sum = 0; n > 0; sum += n % 10, n /= 10);
  
return sum;
}
int main()
{
   int number;
   cout<<"Enter the number between 0 and 1000 inclusive: ";
   cin>>number;
   cout<<"\nThe sum of its digits is "<<getSum(number)<<endl;
}

outputs

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

PLEASE DO THIS IN C#.All Hail Modulus Agustus! The modulus operator is used all the time....
PLEASE DO THIS IN C#.All Hail Modulus Agustus! The modulus operator is used all the time. Realize that if you “mod” any number by a number “n”, you’ll get back a number between 0 and n-1. For example, “modding” any number by 20 will always give you a number between 0-19. Your job is to design (pseudocode) and implement (source code) a program to sum the total of all digits in an input integer number between 0 and 1000, inclusive....
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
As you realize corporations issue long-term debt in the form of bonds all the time. In...
As you realize corporations issue long-term debt in the form of bonds all the time. In Chapter Three we are told that there are different characteristics of these bonds that affect their yields. Given the following bond listing for Ford Motor Credit Company, list and explain the debt characteristics (Credit (default) risk, Liquidity, Tax Status, Term to maturity, Call feature, Conversion feature) as they relate to this bond and if they are adding or subtracting from the yield on this...
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template....
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template. And rewrite your main function to test your template for integer array and double array. Following is my complete code: #include <iostream> using namespace std; class Array { private: // Pointer to memory block to store integers int* data; // Maximum size of memory block int cap; // Stores number of integers in an array int num; public: // Constructor Array(int size); // Default...
please answer with coding from The second edition C programming language textbook /* Changes all occurrences...
please answer with coding from The second edition C programming language textbook /* Changes all occurrences of t in s to u, result stored in v * * Example: * * char v[100]; * replace("hello", "el", "abc", v) => v becomes "habclo" * replace("", "el", "abc", v) => v becomes "" (no change) * replace("hello", "abc", "def", v) => v becomes "hello" (no change) * replace("utilities", "ti", "def", v) => v becomes "udeflidefes" * */ void replace(char *s, char *t,...
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
this is data structures with C++ language, please do "#1 & a" separately and please send...
this is data structures with C++ language, please do "#1 & a" separately and please send me copyable file 1. Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name only once and...
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
(LANGUAGE C++) This time, you will finish the program so that the user gets to solve...
(LANGUAGE C++) This time, you will finish the program so that the user gets to solve the puzzle. You will also use header files and introduce classes into your program. We will follow the draft start to how to incorporate classes. Here are the requirements: ·In the file quotes.h, define the Quotes class: o   Quotes(string filename) // a constructor to load quotes from the named file into a vector o   The vector should be a field of the class so it will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT