Created
December 6, 2018 09:25
-
-
Save dbc2201/15a8a3df3a076f2936187378b595aae8 to your computer and use it in GitHub Desktop.
A program in C to find out the largest prime factor of a number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include<math.h> | |
| long long m(long long n) | |
| { | |
| long long max=-1; | |
| while(n%2==0) | |
| { | |
| max=2; | |
| n/=2; | |
| } | |
| for(int i=3;i<=sqrt(n);i+=2) | |
| while(n%i==0) | |
| { | |
| max=i; | |
| n/=i; | |
| } | |
| if(n>2) | |
| max=n; | |
| return max; | |
| } | |
| int main() | |
| { | |
| long long n; | |
| printf("Enter a number:\n"); | |
| scanf("%lld",&n); | |
| // n=600851475143; | |
| printf("%lld\n",m(n)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment