Question

In: Computer Science

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. 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. Document your code and properly label the input prompts and the outputs as shown below. Sample run 1: Entered number: 123 Sum of digits: 6

Solutions

Expert Solution

Following are the things which you need to take into consideration the above program

  1. We need to use the modulus operator in order to find each digit of the number
  2. We will divide then the number by 10 in order to remove the digit whose sum is already added.

Following is the code for the same in C#

using System;
public class SumOfDigits
{
public static void Main(string[] args)
{
   // Variables     
int n,sum=0,m;
// Print statements before letting the user enter the number
Console.Write("Entered Number: ");
// input the number
n= int.Parse(Console.ReadLine());   
while(n>0)
{
       // Going for each digit from behind
// which will be stored in m
m=n%10;
// Adding the each m in sum
sum=sum+m;
// removing the last digit
n=n/10;
}
Console.Write("Sum of Digits= "+sum);   
}
}

Following is the snippet of the output in a Run.

That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like if you think effort deserves a like.
Thanks


Related Solutions

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...
Please do it in C++. Please comment on the code, and comments detail the run time...
Please do it in C++. Please comment on the code, and comments detail the run time in terms of total operations and Big O complexities. 1. Implement a class, SubstitutionCipher, with a constructor that takes a string with the 26 uppercase letters in an arbitrary order and uses that as the encoder for a cipher (that is, A is mapped to the first character of the parameter, B is mapped to the second, and so on.) Please derive the decoding...
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...
Explain the difference between the modulo operator and the division operator for C#
Explain the difference between the modulo operator and the division operator for C#
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
How do I add an output operator to a class in C++? The specific part of...
How do I add an output operator to a class in C++? The specific part of the task said to: Define a ​class t​o hold accounts. Use the ​same​ stream variable! Write getters to access the fields in the accounts when printing. Add an output operator for your class. First, Repeat the print loop using this output operator.Now​ make the output operator a friend, by adding a friend​prototype​ to your account class definition. Add a line in the output operator...
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.
Please post answers in excel showing all formulas used. Refer to the gasoline sales time series...
Please post answers in excel showing all formulas used. Refer to the gasoline sales time series data in the given table. Week Sales (1000s of gallons) 1 18 2 21 3 19 4 22 5 18 6 16 7 20 8 19 9 23 10 19 11 16 12 22 Compute four-week and five-week moving averages for the time series. Round your answers to two decimal places. Week Sales 4-Week Moving Average 5-Week Moving Average 1 18 2 21 3...
please do all parts a.For resizable array based implementation, what is the time complexity in the...
please do all parts a.For resizable array based implementation, what is the time complexity in the worst and base case scenario? Explain. b. For linked implementation of a list, what is the time complexity in the wort and best case scenario? Explain. remove(givenPosition: integer)
I'll rate posting for 3rd time please do all parts  you gotta do is "job cost sheet"...
I'll rate posting for 3rd time please do all parts  you gotta do is "job cost sheet" , "journal", and final question Maria Young is the sole stockholder of Purl of Great Price Company (POGP Company), which produces high-end knitted sweaters and sweater vests for sale to retail outlets. The company started in January of the current year, and employs three knitters (each of whom work 40 hours per week) and one office manager/knitting supervisor (this employee works 20 hours per...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT