Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : Arifin
- Date : 01/06/11 10:09
- Description : Menentukan perfect number dengan algoritma 2
- */
- #include<iostream>
- #include<conio.h>
- #include<math.h>
- using namespace std;
- int main()
- {
- long jumlah=1,x,i,
- y,//batas
- z;//hasil
- cout<<"Program menentukan suatu bilangan perfect number atau bukan"<<endl<<endl
- <<"=================="<<endl
- <<"Masukkan bilangan: ";cin>>x;
- for (i=2;i<=y;i++)
- {
- if (x%i==0)//2:y=13;i=4,y=13;
- {
- cout<<"i= "<<i<<endl<<endl;
- jumlah+=i;//jumlah=1+2=3;jumlah=17+4=21;
- cout<<"*"<<jumlah<<endl<<endl;
- z=x/i;//z=28/2=14;z=28/4=7
- if(z!=i)//terpenuhi;terpenuhi
- jumlah+=z;//jumlah=14+3=17;jumlah=21+7=28
- y=z-1;//y=13;y=6
- cout<<jumlah<<endl<<endl;
- }
- }
- cout<<jumlah<<endl;
- if (jumlah==x)
- cout<<x<<" merupakan perfect number";
- else
- cout<<x<<" bukan perfect number";
- getch ();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement