top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find largest prime factor of a positive integer?

+3 votes
243 views

Please help me by sharing algo or C code?

posted Mar 19, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The following program only help you to find the largest prime factor of a number.

#include <stdio.h>

int main()
{
    long long  number;
    printf("Enter a number to know its largest prime factor: ");
    scanf("%lld",&number);
    long long div=2, ans = 0, maxFact;
    while(number!=0){
        if(number % div !=0)
            div = div + 1;
        else{
            maxFact  = number;
            number = number / div;

            if(number == 1){
                printf("%d is the largest prime factor !",maxFact);
                ans = 1;
                break;
            }
        }
    }
    return 0;
}
answer Mar 24, 2015 by Manikandan J
Similar Questions
0 votes

Given an unordered array A of size n and integer x. What is the best complexity to find two elements in A whose sum is x?
Share the algo, its complexity and if possible C code.

+6 votes

I was trying to get maximum rectangle area for a given histogram but I used brute force approach which have O(n^2) time complexity so I want some better solution using stack so that we could reduce time complexity to O(n) or O(log n ).

+2 votes

How to find prime numbers between given intervals? Sample code along with the complexity would be helpful?

...