Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Program for Find the largest prime factor of a number?
Prime Factor− In number theory, the prime factors of a positive integer are the prime numbers that divide that integer exactly. The process of finding these numbers is called integer factorization, or prime factorization.
Example− Prime factors of 288 are: 288 = 2 x 2 x 2 x 2 x 2 x 3 x 3
Input: n = 124 Output: 31 is the largest prime factor!
Explanation
You will find all the prime factors of a number and find the largest of them. The prime factors 124 = 2 x 2 x 31. and 31 is the largest of them.
Example
#include <stdio.h>
int main() {
long int n;
n=3453;
long int div=2, ans = 0, maxFact;
while(n!=0) {
if(n % div !=0)
div = div + 1;
else {
maxFact = n;
n = n / div;
if(n == 1) {
printf("%d is the largest prime factor !",maxFact);
ans = 1;
break;
}
}
}
return 0;
}
Output
1151 is the largest prime factor !
Advertisements