c - Determine the largest prime factor -
i'm trying run brute force algorithm determine highest prime factor of number. here's code in c
#include <stdio.h> #include <stdlib.h> long checkforhighestprime(long param); int main(){ printf("%ld",checkforhighestprime(600851475143l) ); return exit_success; } long checkforhighestprime(long param){ long d= 0; long h = 0; long i; (i = 1; <param; i++){ //check if it's factor d = param%i; // if it's factor determine whether prime if(d == 0){ for(long j = 0; j<i ; j++){ if (d%j == 0){ break; }else{ h = d; } } } } return h; } however end following error
floating point exception: 8 what missing?
in inner for loop, initialize j 0. causes d % j == 0 throw exception because attempting divide zero. also, appears d should i.
Comments
Post a Comment