Quote:
Finding the largest prime factor of a number using a C program
If you input 1, your program will say that the largest prime factor is 2. I suspect an error.
You also need to handle the result for 0 and negative numbers to be complete.
You can simplify your code
while(a!=1)
{
if(a%i==0) {
while(a%i==0) {
a = a/i;
printf("%d ",i);
if(i>largeprimefactor)
{
largeprimefactor = i;
}
}
}
i++;
}
[Update]
You can even simplify more.
while(a!=1)
{
if(a%i==0) {
while(a%i==0) {
a = a/i;
printf("%d ",i);
if(i>largeprimefactor) {
largeprimefactor = i;
}
}
}
i++;
}