Point-1
You have misspelled largest
in function name
long largetsprime(long)
^
s is wrong here
In declaration It should be
long largestprime(long)
^ before t
Point-2
You are using sqrt()
library function from math.h
, you should compile your program with -lm
as:
gcc -Wall -std=c99 -pedantic primefactors.c -lm
Point-3
You are returning int
whereas return type of your function is long
.
Point-4
One more mistake suggestion in call of printf()
you forgot adding suffix for long int
.
largestprime(600851475143)
should be:
largestprime(600851475143L)
// ^ added suffix L for long
If you are not aware of suffix L
then read: What does the “L” mean at the end of an integer literal?
Thanks to @Eric Postpischil:
point-5: printf()
in main()
function is printing long
type integer whereas you have used %d
format specifier to print it:
printf("%d\n", largestprime(600851475143));
^
|
returns long
use %ld
instead.
point-6:
if
-condition in largest prime function i % 1 == 0 and i % i == 0
are each always true (except the latter is undefined if i
is zero) because i % 1
= 0
(every number is divisible by 1
).