I am getting a problem with following code that "Floating point exception, core dumped" but I have not even one float or double variable. By using checking printf, i observed that it happens in isPrimeFunction, where there execution jams.
/*
PROBLEM 3
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
*/
#include <stdio.h>
typedef int bool;
const bool true=1;
const bool false=0;
bool isPrime(long long int number) {
long long int i;
for(i=2; i < (number/2); i++) {
if(number%i == 0) {
return false;
}
}
return true;
}
int main() {
long long int number, largest;
number=600851475143;
largest=0;
int i;
for(i=1; i <= (number/2); i++) {
if((number % i) == 0) {
if(isPrime(i) == true) {
largest=i;
}
}
}
if(largest != 0)
printf("Largest prime factor is: %lli\n", largest);
else
printf("There is no prime factor of the number.\n");
return 0;
}