Sunday, 14 June 2009

Prime factor

Description:-
In our mathematics it is very important to find out the factors(prime) of a number.
For example:
Given number=12
Factors= 2,2,3
Sometimes this task will be difficult if there is a number greater than 1000 or very huge number, then you need very long time to find the factors of that given number.
Through this program you can quickly find out the prime factors of the given number.
You need to give that number as input automatically factors are coming out as a result.

Process:-
1. Copy the entire source code(Bold in format).
2. Paste that in your c or c++ compiler.
3. Save that with a suitable name.
4. Compile that program.
5. Finally run that program.

Error handling:-
Due to inappropiate html coding done by this web page I can't give the header file
name like stdio.h, conio.h, stdlib.h, iostream.h, fstream.h, iomanip.h etc.
If u get an error report after compiling the program
"CALL TO UNDEFINED FUNCTION 'PRINTF(OR ANYTHING)' IN FUNCTION MAIN()"
please add the above mentioned header file after #include
like #include.

Disclaimer:-
If you have any other problem regarding the program please mail me.
My mail address is showing on my blog page.


Source code:-

/*This program helps to find the factor of a given number*/
#include
void main()
{
long i,n;
clrscr();
printf("Enter a number=>");
scanf("%ld",&n);
for(i=2;i<=n;i++)
{
while(n%i==0)
{
n=n/i;
printf("%ld ",i);
}
}
}

0 comments: