Write a program to break down the accepted number to its prime factors numbers.
Enter number 5
5 = Prime
Enter number 100
100 = 2 * 2 * 5 * 5
#include <iostream.h>
void main()
{
int n,i,on;
cout << "Enter number(greater than or equal 2)";
cin >> n;
on=n;
i=2;
cout << endl << n << "= " ;
while(n>i)
{
if(n%i==0)
{
cout << i << "*";
n=n/i;
}
else
{
i=i+1;
}
}
if(on==n)
cout << "Prime";
else
cout << i;
}
No comments:
Post a Comment