Question
What does the following C function compute? Discover.
int some fun(int n)
{
if(n%2 == 0)
return 2;
int d, s = sqrt(n);
2
for(d = 3; d <= s; d = d+2)
if(n%d == 0)
return d;
return n;
}
Answer :
Word Count : 185
_________ _________ _____ ___ ________ __________ ___ ___ _______ ___ _______ ___.
________ ___ ___ ____ ________ _____.
________ ______ ____ ___ _______ ______ _________ __________ ___ ________ ______.
_____ ______ _____ ___ ______.
_____ ____ ___ ___ _______ ___ _______ ___ __________ _________.
_____ _________ ___ _____ __________.
____ __________ _____ _________ ____ ________ _____ ____ _____ ___ ____ ________.
__________ ______ ________ _______ ____ _____ ________ ________ _________ __________.
____ ____ _______ ______ _____ ___ ___ _________ _________ ______.
_______ __________ ___ __________ _______ _______.
______ ___ ____ ______ _______ ________ ________ ________ _____ ____ ___ __________.
_________ ___ _______ _____ ____ _________ _____ ________ __________ ___ __________.
____ _____ ____ ___ ___ _________ ______ _____ ________ _____ _________.
____ _____ _________.
Skip in 10
This C function appears to compute the smallest prime factor of a given integer `n`. Here's how it works:
1. If `n` is even (`n % 2 == 0`), the function immediately returns `2`, which is the smallest prime factor of any even number.
2. If `n` is odd, it calculates the square root of `n` and assigns it to the
________ ___ ___ ____ ________ _____.
________ ______ ____ ___ _______ ______ _________ __________ ___ ________ ______.
_____ ______ _____ ___ ______.
_____ ____ ___ ___ _______ ___ _______ ___ __________ _________.
_____ _________ ___ _____ __________.
____ __________ _____ _________ ____ ________ _____ ____ _____ ___ ____ ________.
__________ ______ ________ _______ ____ _____ ________ ________ _________ __________.
____ ____ _______ ______ _____ ___ ___ _________ _________ ______.
_______ __________ ___ __________ _______ _______.
______ ___ ____ ______ _______ ________ ________ ________ _____ ____ ___ __________.
_________ ___ _______ _____ ____ _________ _____ ________ __________ ___ __________.
____ _____ ____ ___ ___ _________ ______ _____ ________ _____ _________.
____ _____ _________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.