Advertisement
SMASIF

Prime Factors

Aug 22nd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int i, j, num, isPrime;
  6.     cout<<"Enter Number: "<<endl;
  7.     cin>>num;
  8.  
  9.     cout<<"Prime factors of "<<num<<" are: "<<endl;
  10.  
  11.     for(i=2; i<=num; i++)
  12.     {
  13.         if(num%i==0)
  14.         {
  15.             isPrime = 1;
  16.             for(j=2; j<=i/2; j++)
  17.             {
  18.                 if(i%j==0)
  19.                 {
  20.                     isPrime = 0;
  21.                     break;
  22.                 }
  23.             }
  24.             if(isPrime==1)
  25.             {
  26.                 cout<<i<<endl;
  27.             }
  28.         }
  29.     }
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement