# Thread: Finding the highest prime factor of a number with a C program

1. ## Finding the highest prime factor of a number with a C program

I created a program which finds the highest prime factor of a number.
But there is a problem in it. It is working fine till 9 digit numbers. After that it is showing weird numbers as answers.

Code:
```#include<stdio.h>

int largestprimefactor(unsigned long a)
{
int i =2 ,largeprimefactor = 2;

while(a!=1)
{
if(a%i==0)
{
while(a%i==0)
{
a = a/i;

printf("%d ",i);

if(i>largeprimefactor)
{
largeprimefactor = i;
}
}
}

i++;
}

return largeprimefactor;
}

main()
{
unsigned long inputnumber;

printf("Enter a number : ");
scanf("%d",&inputnumber);

printf("\nThe largest prime factor of %d is %d",inputnumber,largestprimefactor(inputnumber));
}``` 2. 9 digits is about all you can store in an unsigned long number. 3. Then which data type I should use? Should I use long keyword 2 times? 4. What is the range of numbers that you wish to handle?

If they are within the range of an unsigned long long (guaranteed to have a maximum at least equal to the maximum for a 64 bit unsigned integer in the range starting from 0), and if your compiler supports that, you could use that instead. 5. Be careful if you're on windows, even if you're using code::blocks or MinGW as your compiler.
Size Specification
Depending on how old your C runtime library is on your machine, you may need to use alternative format specifiers to print 64-bit integers. 6. Okay. 7. I want to use numbers from 0 to 9 digit numbers. Popular pages Recent additions c programming, factor, int, number, prime 