Basically, a program to find the largest prime factor of a number. Don't know if the logic is correct cuz I can't run it to test it. I know this is long. But please forgive me.
//largest_prime.c
#include <stdio.h>
int main() {
int num,large;
int prime(int);
int lprime(int);
printf("Enter number: ");
scanf("%d",&num);
large = lprime(num);
printf("Largest Prime = %d\n",large);
return 0;
}
int lprime(int num) {
int i=num-1,large;
while (i!=-1) {
if (num%i==0) {
if (prime(i)==1) {
large=i;
i=-1;
}
i--;
}
return large;
}
int prime(int num) {
int prime,i=num-1;
while (i!=-1) {
if(num%i==0) {
if(i!=1) {
i=-1;
return 0;
}
else
return 1;
}
i--;
}
}
I get this as output at terminal (I use Mac) using GCC:
largest_prime.c: In function ‘lprime’:
largest_prime.c:26: error: nested functions are disabled, use -fnested-functions to re-enable
largest_prime.c:39: error: syntax error at end of input
I tried -fnested-functions to re-enable. I get:
largest_prime.c: In function ‘lprime’:
largest_prime.c:39: error: syntax error at end of input
Please Help!