Answered step by step
Verified Expert Solution
Link Copied!

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 1: Enter a positive integer
int positiveNumber;
do {
std::cout << "Enter a positive integer: ";
std::cin >> positiveNumber;
// Step 2: Validate input (Check if positive)
if (positiveNumber <=0){
std::cout << "Please enter a positive integer.
";
}
} while (positiveNumber <=0);
// Step 3: Initialize variables
int divisorSum =0;
int divisorCount =0;
// Step 4: For each number i from 1 to entered number
for (int i =1; i <= positiveNumber; ++i){
// Step 5: Check if i is a divisor
if (positiveNumber % i ==0){
// Step 6: If i is a divisor, print i, add i to divisor_sum, and increment divisor_count
std::cout << i <<" is a divisor.
";
divisorSum += i;
divisorCount++;
}
}
// Step 7: Calculate and print the average of divisors
if (divisorCount >0){
double average = static_cast(divisorSum)/ divisorCount;
std::cout << "Average of divisors: "<< average <<"
";
} else {
std::cout <<"No divisors found.
";
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

Recognize the various roles and competencies of an HRD professional

Answered: 1 week ago

Question

Define human resource development (HRD)

Answered: 1 week ago