Question

C++2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parame

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ program :-

#include <iostream>

using namespace std;

void printdivisors(int num){
for (int i=1;i<num;i++)
if (num%i==0)
cout<<i<<" ";
}

int sumdivisors(int num){
int sum=0;
for (int i=1;i<num;i++)
if (num%i==0)
sum=sum+i;

return sum;
}

void allperfects(int low_range, int high_range)
{
for(int i=low_range;i<=high_range;i++)
{
int sum=0;
for (int j = 1; j <= (i - 1); j++)
{
int rem = i % j;
   if (rem == 0)
{
sum = sum + j;
}
}
if (sum == i)
cout<<i<<" ";
}
}

int main()
{
cout<<"Print divisors :"<<endl;
printdivisors(6);
  
cout<<endl<<"The perfect numbers :"<<endl;
allperfects(1,20);
  
cout<<endl<<"The sum of divisors :"<<sumdivisors(6)<<endl;

}

Output :-

Ex Result CPU Time: 0.00 sec(s), Memory: 3324 kilobyte(s) Print divisors : 1 23 The perfect numbers : The sum of divisors :6

Add a comment
Know the answer?
Add Answer to:
C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT