perfect number ..

#include<iostream.h>

#include<conio.h>


using namespace std;

int main()

{

char tanya;

int bilangan,jumlah,i,sum,x;

system(“cls”);

cout<<” | ================================ |”<<endl;

cout<<” | Program Perfect Number [ 1..1000 ] |”<<endl;

cout<<” |================================ |”<<endl<<endl;

cout<<endl;

cout<<“ Perfect Number [1..1000] adalah : ” ;

cout<<endl;

for(int i = 1; i < 1000; i++)

{

sum = 0;

for(int j = 1; j < i; j++)

{

if(i % j == 0) sum += j;

}

if(sum == i)

{

cout<<endl;

cout << ” ” << i << ” = ” ;

for (x=1;x<=sum-1;x++)

{

jumlah = sum%x;

if (jumlah==0)

{

if (x < sum/2)

cout<<x <<” + ” ;

else

cout<<“” <<x;

}

}

}

}

cout<<endl;

cout<<endl;

system(“pause”);

return 0 ;

}

perfect_number

Posted in Struktur Control | Tagged , , | Leave a comment

hitung prima 1-500 ..

#include<iostream.h>

#include<conio.h>

using namespace std;

int main()

{

char tanya;

int bilangan,jumlah,prima;

do

{

system(“cls”);

cout<<” | =============================== |”<<endl;

cout<<” | Program Penghitung Bilangan Prima [ 1..500 ] |”<<endl;

cout<<” |================================ |”<<endl<<endl;

cout<<“ Masukkan Bilangan : “;

cin>>bilangan;

cout<<endl;

cout<<“ Faktor – Faktor Bilangan : ” ;

cout<<endl;

while(bilangan<1 || bilangan>500);

for(int i=1;i<=bilangan;i++)

{

prima=1;

for(int j=2;j<i;j++)

{

if(i%j==0) prima–;

}

if (prima==1)

{

printf(“ %d “, i);

}

}

cout<<endl;

cout<<endl;

cout<<“ Ingin Hitung Kembali (y/t)?”;

cin>>tanya;

} while(tanya==’y’);

return 0;

}

bilprima

Posted in Struktur Control | Tagged , | Leave a comment