English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

We have to find the prime factors of a no & display it like - for the no 6, the prime factors are 1*2*3.

2006-12-09 04:21:51 · 2 answers · asked by jags 1 in Computers & Internet Programming & Design

2 answers

#include
#include

int prime(int x)
{
int y=sqrt(x);
int j=0;
for(int i=2;i {
if(x%i==0)
y=1;
}
return y
}

int main()
{
int a;
cout<<"Enter Any Number: ";
cin>>a;
cout< for(int i=2;i<=a;i++)
if(a%i==0)
if(prime(i))
cout<<", "< return 0;
}

// Enjoy ;)

2006-12-09 04:33:12 · answer #1 · answered by Ahmad Nasser 2 · 0 0

1 is not a prime factor btw.
So if n is the number, just search from 2 to (n/2)+1, and see if they are prime and divide with n. If they do then they are prime factors.
There is a theorem which demonstrates that all prime factors for n are located between 2 and (n/2).

2006-12-09 12:25:46 · answer #2 · answered by agent-X 6 · 0 0

fedest.com, questions and answers