Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int jumlah=0;
- bool prima(int x)
- {
- int jumlah = 0;
- for(int i =1;i<=x;i++)
- {
- if(x%i==0)
- jumlah++;
- if(jumlah>2)
- break;
- }
- if(jumlah>2)
- return false;
- else
- return true;
- }
- int hitung(int x)
- {
- if(x==1)
- {
- return 0;
- }
- for(int i =2; i<=x;i++)
- { jumlah=0;
- if(prima(i))
- {
- if(x%i==0)
- {
- while(x%i==0)
- {
- jumlah++;
- x=x/i;
- }
- cout<<i<<"^"<<jumlah;
- if(x!=1)
- cout<<" x ";
- return hitung(x);
- }
- }
- }
- }
- main()
- {
- int num,jumlah;
- int sisa;
- cout<<"masukan angka : ";cin>>num;
- cout<<"faktorisasi primanya adalah : ";
- hitung(num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement