Advertisement
add1ctus

Факторизација

Sep 30th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void faktoriziraj(int a)
  6. {
  7.     if(a==1)
  8.         cout<<1<<endl;
  9.     else
  10.     {
  11.         for(int i=2;i<=a;++i)
  12.         {
  13.             if(a%i==0 && a!=i)
  14.             {
  15.                 cout<<i<<"*";
  16.                 faktoriziraj(a/i);
  17.                 break;
  18.             }
  19.             else if(a==i)
  20.             {
  21.                 cout<<i<<endl;
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.     int n;
  30.     cin>>n;
  31.     for(int i=1;i<=n;i++)
  32.     {
  33.         cout<<i<<" = ";
  34.         faktoriziraj(i);
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement