Question

Write a function named factorCount that accepts an integer (assumed to be positive) as its parameter...

Write a function named factorCount that accepts an integer (assumed to be positive) as its parameter and returns a count of its positive factors. For example, the eight factors of 24 are 1, 2, 3, 4, 6, 8, 12, and 24, so the call of factorCount(24) should return 8. Program is c++

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

#include <iostream>

#include <string>

using namespace std;

int factorCount(int n){

    int count =0;

    //counting the factors using for loop

    for(int i=1; i<=n; i++){

        if(n%i ==0){

            count++;

        }

    }

    return count;

}

int main(){

    //Getting the number from user and calling the factor count function

    int n=0;

    cout<<"Enter the number: ";

    cin>>n;

    int count = factorCount(n);

   //printing out the results

    cout<<"Number of factors of "<<n<<": "<<count<<endl;

}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a function named factorCount that accepts an integer (assumed to be positive) as its parameter...
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