My code in c is giving wrong output -
i wrote code in c, find largest prime factor of number i, , gives j=5102831, prime not factor of i.
the code seems write me, feels there wrong compiler.
so, please copy code , check output it's giving.
#include <stdio.h> int prime (int); int main() { int i=600851475143,j; j=i-1; ( ; ; j--) { if ((i%j) ==0) if(prime(j)) return (j); if (j==2) break; } return 0; } int prime (int j) { int k; for(k=2; k<=j-1; k++) if((j%k)==0) return 0; return 1; }
i think mean
if ((i%j) !=0) ^^^ if(prime(j)) return (j);
also take account 2 prime number.
Comments
Post a Comment