i need a c program that displays all factors of a number including one and itself. I can't use arrays, pointers, and strings. I am also not allowed to use other libraries... only stdio.h. help anyone?
Need help in C programming?
Use the mod operator %.
Remember 0 is equivalent to false, and anything else is equivalent to true in C, so you don't need to waste system time with a comparator like (==).
10 % 2 returns false, and that means it's a factor wile
10 % 3 returns true, and that means it's not a factor
the highest factor for any number is that number divided by 2, and the number itself and 1 will always be a factor.
Reply:Well the best way to do this would be to iterate from 1 through to the square root of the number desired. then divide the number by each one, test if fpart(number/possiblefactor) == 0. If it does equal zero then print the possible factor and the result of the division.
Finally check if the number is a perfect square and print that too if it is.
Reply:what is C programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment