Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to write a C++ program. Additive persistence is a property of the sum of the

ID: 3783438 • Letter: H

Question

How to write a C++ program.

Additive persistence is a property of the sum of the digits of an integer. The sum of the digits is found, and then the summation of digits is performed creating a new sum. This process repeats until a single integer digit is reached.

Consider the following example:

1. The beginning integer is 1234

2. Sum its digits is 1+2+3+4 = 10

3. The integer is now 10

4. The sum of its digits is 1 + 0 = 1

5. The integer is 1. When the value reaches a single digit, we are finished. This final integer is the additive root

Program Specifications The program should run as follows.

1) Gather input as a redirection from a file input.txt. The program ends under one of the following circumstances

a. the next gathered integer is a negative number. b. if all the integers from the file have been processed.

2) If the given integer is a single digit, report its additive persistence as 0 and its additive root as itself on a single line as two space separated numbers

3) For each multidigit, non-negative, integer output on a single line the two space separated numbers:

a. the integer's additive persistence

b. the integer's additive root

How to write a C++ program.

only use those Numbers and Operations Number forms Numeric Operations Assignment Booleans and Relational Ops Booleans and Relational Ops Control if while counting for continue, break and nested loops count and classify characters in a file switch and ternary

input.txt

3

output.txt should be like this

which is 1st. the integer's additive persistence 2nd. the integer's additive root

Explanation / Answer

#include<iostream>

using namespace std;

int main()

{

    int val, num, sum = 0;

    cout << "Enter the number : ";

    cin >> val;

    num = val;

    while (num != 0)

    {

        sum = sum + num % 10;

        num = num / 10;

    }

    cout << "The sum of the digits of "

         << val << " is " << sum;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote