Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include int main ( ) { / / Step 1 : Enter a positive integer int positiveNumber; do { std::cout < < Enter a positive
#include
int main
Step : Enter a positive integer
int positiveNumber;
do
std::cout "Enter a positive integer: ;
std::cin positiveNumber;
Step : Validate input Check if positive
if positiveNumber
std::cout "Please enter a positive integer.
;
while positiveNumber ;
Step : Initialize variables
int divisorSum ;
int divisorCount ;
Step : For each number i from to entered number
for int i ; i positiveNumber; i
Step : Check if i is a divisor
if positiveNumber i
Step : If i is a divisor, print i add i to divisorsum, and increment divisorcount
std::cout i is a divisor.
;
divisorSum i;
divisorCount;
Step : Calculate and print the average of divisors
if divisorCount
double average staticcastdivisorSum divisorCount;
std::cout "Average of divisors: average
;
else
std::cout No divisors found.
;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started