Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
For example, if the function is called with the value 10 as numberand 5 as primeFactor, the function should return 1 indicating that 5 is a prime factor of 10. Similarly, the function should return 0 if the numberin the example was 9. And also I was recommended to look into the use of modulus..?

What I have tried:

I tried to make a function that factorises a number, so that I then could check the prime factors and determine if the second number was one of those, but I am completely new to programming so any tips would be great!
Posted
Updated 2-Sep-18 10:16am

That is a nice homework for you, so I will give you only some tips.

a) you must only check til the half value of input (means x/2 * 2)
b) write some function and use understandable namens with some output
c) use some test cases

For more detailed approaches you may search the internet.
 
Share this answer
 
Comments
[no name] 2-Sep-18 14:51pm    
What do you like to Point out with "means x/2 * 2"?
x/2*2= x.....
Anyway x^(1/2) = sqrt(x) will do it.
Quote:
Write a C function that determines whether a number have a given prime factor?

What is the result if second number is not a prime?
If result is same, you just have to find if second number is a factor of first one. Second number being a prime does not matter.

Quote:
And also I was recommended to look into the use of modulus..?

Always read documentation.

Quote:
but I am completely new to programming so any tips would be great!

Show your code to get help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900