top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find Prime factors of a number in c in best available approach?

+2 votes
300 views
How to find Prime factors of a number in c in best available approach?
posted Nov 4, 2014 by anonymous

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

1 Answer

+1 vote
#include <stdio.h>

int main()
{

    int number,div;    
    printf("Enter a number to know its prime factor: ");    
    scanf("%d",&number);

    printf("\nThe prime factors of %d are: \n\n",number);

    div = 2;

    while(number!=0){
        if(number%div!=0)
            div = div + 1;
        else {
            number = number / div;
            printf("%d ",div);
            if(number==1)
                break;
        }
    }
    return 0;
}
answer Dec 1, 2014 by Shivaranjini
...