Write a C++ program divisorsum.cpp which which reads numbers, one at a time, from the terminal input, and outputs the proper divisors and the proper divisor sum for that integer in an equation format.
Here is an example:
> divisorsum 6 6: 1+2+3 = 6 888 888: 1+2+3+4+6+8+12+24+37+74+111+148+222+296+444 = 1392 0 >
Note: spaces will be ignored, but punctuation symbols (:+=) must be in the correct places.
Your program should handle the calculation of proper divisor sums for all numbers between 2 and 2147483647.
Your program should continue answering about the proper divisor sums of numbers until 0 is entered, at which time the program should exit silently.
Hello, here is the completed code you wanted. Every important statement is explained using comments. Please check and let me know if you have any doubts. Thanks.
CODE
#include<iostream>
using namespace std;
//main function
int main()
{
int number;
unsigned int sum;
//repeat until number is 0
while(true)
{
//prompt for number
cout<<"\nEnter a number:
";
cin>>number;
//if number is zero
if(number == 0)
//break from the
loop
break;
//initialize sum as 1
sum = 1;
//printing number and 1
cout<<number<<":
1";
for(int i = 2; i < number;
i++)
{
//if i is a
proper divisor of number
if(number % i ==
0)
{
//print + and i
cout<<"+"<<i;
//calculating sum
sum = sum + i;
}
}
//printing sum
cout<<" = "<<sum;
}
}
OUTPUT

CODE SCREEN SHOT


Write a C++ program divisorsum.cpp which which reads numbers, one at a time, from the terminal...
2 Happy Numbers 2.1 Definition The definition of a happy number, from wikipedia Given a number n = no, define a sequence n1, n2, … where ni+1 1S the sum of the squares of the digits of n,. Then n is happy if and only if there exists i such that ni 1 It can be shown (see wikipedia) that n is unhappy if the number 4 appears in the sequence. 2.2 The program Write a C++ program happy.cpp which...
write a c++ program that reads some numbers from a text file then it displays how many of these numbers composed of the same digit For example(444 22 232 78 1111) so the program should displays 3 (using only while loops and if statment)
Write a Python program to print all Perfect numbers between 1 to n. (Use any loop you want) Perfect number is a positive integer which is equal to the sum of its proper positive divisors. Proper divisors of 6 are 1, 2, 3. Sum of its proper divisors = 1 + 2 + 3 = 6. Hence 6 is a perfect number. *** proper divisor means the remainder will be 0 when divided by that number. Sample Input: n =...
Instructions In c++ write a program that reads in a string of zeros and ones without spaces and for each 8 digits (one byte) outputs the corresponding value in decimal format. The output numbers are separated by spaces. Stop when a character different than 0 or 1 is encountered. The final output may be generated from less than 8 digits but no output should be generated for the final character. Should work for example: input: 00000011000000010010X output: 3 1 2
Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and, on the output, writes the sum of the divisors of n (other than itself). For integers less than or equal to 1 it should print 0. For example, the input -3 0 1 4 5 6 12 should generate the output 0 0 0 3 1 6 16 Explanation of output: The input -3 is less than 1, output is 0. The input 0...
4. Write a C++ program (or Java program) w that reads two groups of numbers in which each group has random integer numbers with possible duplicates. Your program should display the common numbers without any duplicates in the ascending order. Input format: This is a sample input from a user. cik length WC tontu
In C++, write a program that reads a postfix expression from an input file. Then, the program should evaluate the postfix format and display the results. Use these concepts for the program: 1) Struct Node 2) Enqueue and Dequeue 3) Push and Pop 4) DO NOT USE classes 5) Possibly Stack Precondition: The expression will be read from a file (input.txt) that contains a single line. There will be no spaces between the operands and the operators. The following operators...
use python: Write a program that reads in X whole numbers and outputs (1) the sum of all positive numbers, (2) the sum of all negative numbers, and (3) the sum of all positive and negative numbers. The user can enter the X numbers in any different order every time, and can repeat the program if desired. Sample Run How many numbers would you like to enter? 4 Please enter number 1: 3 Please enter number 2: -4 Please enter...
I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...
Write a ( JAVÅ) program which reads (from the keyboard) numbers (doubles) until a zero is input and computes the maximum and minimum of all the read numbers (excluding the terminating zero). Note: you must allow for negative as well as positive numbers. Hint: look at java.lang.Double.MAX_VALUE and java.lang.Double.MIN_VALUE.