1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Natalka [10]
3 years ago
13

Digits Sum Write a function main( that reads a positive integer, calls the function digits which finds the digits sum of that in

teger. The function main( prints the sum. Sample input/output: Enter a positive integer: 20010 The digits sum of 20019 is 3
Computers and Technology
1 answer:
djyliett [7]3 years ago
4 0

Answer:

#include<iostream>

using namespace std;

int digits(int number){

   int sum=0;

   while(number != 0){

       int rem = number % 10;

       sum = sum + rem;

       number = number/10;

   }

   return sum;

}

int main(){

   int number;

   cout<<"Enter the integer: ";

   cin>>number;

   int result = digits(number);

   cout<<"The sum of digits is: "<<result<<endl;

}

Explanation:

Include the library iostream for use of input/output.

Then, create the function digits with return type int.

Take a while loop and put a condition number not equal to zero.

the while loop executes the until the condition is not false.

In the while loop, take the remainder of the number and store in the rem variable.

after that, the store in the sum then reduces the number by dividing 10.

for example:

the number is 123.

rem = 123%10 it gives the value 3.

sum = 0+3=3

number = 123/10 it equal to 12

then,

rem = 12%10 it gives the value 2.

sum = 3+2=5

number = 12/10 is equal to 1

the same process executes until the number becomes zero and then the while loop terminates and the sum value returns to the main function.

create the main function and take the value from the user and call the function with the argument number.

and finally, print the result.

You might be interested in
What is statement used to communicate ones feelings in a nonconfrontational manner
makkiz [27]

"I am" statements are very well to communicate with people about your feelings in a non confrontational manner.


6 0
3 years ago
The most frequently applied heuristic in problem solving is a(an) _________, which involves repeated tests for differences betwe
Dvinal [7]

Answer:

means-ends analysis

Explanation:

<h2><u>Fill in the blanks</u></h2>

The most frequently applied heuristic in problem solving is a <u>means-end analysis,</u>  which involves repeated tests for differences between the desired outcome and what currently exists.

8 0
4 years ago
What is the danger of open-source software when it comes to military robotics?
Murljashka [212]

Answer:

The issue with open source software is that it is usable (and editable) by anyone. When it comes to military robotics, the software that is used to run the robots must remain confidential. If it is not, anyone could take the software that the military is using to make their robots function and replicate it, which could be extremely dangerous.

Explanation:

Open source software is available to the general public.

Feel free to copy and paste this or put it into your own wording. Have a nice day!

4 0
3 years ago
I am in need of a research topics in networking and security?​
cricket20 [7]
No, you will be fine.
8 0
4 years ago
Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are
asambeis [7]

Answer:

We can use comparison operator 'Equals to' (==) to compare two strings.

Explanation:

We can use conditional statement 'if else' to put conditions. If statement contains boolean expression.If statement is followed by else block. If the boolean expression evaluates to true, then the if block of code is executed, otherwise else block of code is executed.

If we want to compare two strings with uppercase, then we can convert the input strings given by users using ToUpper() string function.

For example,

 string abc;

string uppercase= abc.ToUpper(); // gives ABC as result

I have written a program using c# as a  programming language in a word document and attached the same. Please find. Thank you!

Download doc
5 0
4 years ago
Other questions:
  • Smartphones store their operating system software in ________.
    11·1 answer
  • These are the characteristics of good blogs.
    11·1 answer
  • Your computer is slowing down because you’ve started a process that is taking most of the memory and CPU resources. Which of the
    7·1 answer
  • A Windows user has been successfully saving documents to the file server all morning. However, the latest attempt resulted in th
    9·2 answers
  • Differences between the first four generations of computers​
    12·1 answer
  • Which quality allows programmers to modify a program as and when required
    11·2 answers
  • To which of these options does the style in Word apply? Select three options.
    7·1 answer
  • Write a C++ program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liqu
    14·1 answer
  • Using the simple alphabet code below, you will decode and encode the message. Write the Full
    6·1 answer
  • The space that helps you organize your PowerPoint or Web Page is called ______.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!