Tuesday, 30 April 2013

PROGRAM FOR FINDING THE PRIME FACTOR OF A NUMBER

The prime factors of a positive integer are the prime numbers that divide that integer exactly.
for example :-





Here is the source code for finding the prime factors of any number inputted by the user. Here you should note that that to increase the range I have used long data type to store number given by user.

Source code :-
/**********************************************************************************/
#include<stdio.h>
#include<conio.h>

int main()
{
    long num,i,a;
    clrscr();
    printf("ENTER THE NUMBER : ");
    scanf("%ld",&num);
    a=num;
    for(i=2;i<=a;i++)
    {
        if((num%i)==0)
        {
            printf("%ld\t",i);
            num/=i;
            i=1;
        }
    }
    getch();
    return 1;
}
/*********************************************************************************/
Output :-


No comments:

Post a Comment