top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

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

+2 votes
65 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...