Spoiler for :
Code:
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int cek;
int random1 = rand()%9+1;
int random2 = rand()%9+1;
cout<<"Range Dari";
cout<<" "<<random1<<" "<<"Sampai"<<" "<<" "<<random2; //Hasilnya 6 sampai 9
cout<<endl;
for(int i = random1; i<=random2 ; i++){
//cout<<i<<" "; ngecek i dan hasilnya 6,7,8,9
[color=red]if(i%i == 0 && i!= i){
cek = cek + i;
}
if(cek == i ){
cout<<i<<" "<<"Bilangan Sempurna";
cout<<endl;
// Bilangan Sempurna adalah 6, 28, 496, 8128
}
else
cout<<i<<" "<<"Bukan Bilangan Sempurna";
cout<<endl;[/color]
}
return 0;
}
Yang dimerahin berasal dari program ini.
Spoiler for :
Code:
#include<iostream>
using namespace std;
int main(){
int input;
int temp;
int cek = 0;
cin>>input;
for(int k=1; k<=input; k++){
if(input%k == 0 && input != k){
cek = cek + k;
}
}
//cout<<temp<<endl<<endl;;
if(cek == input){
cout<<"Bilangan Sempurna";
// 6, 28, 496, 8128
}
else
cout<<"Bukan Bilangan Sempurna";
return 0;
}
Tapi aku bingung kok hasilnya malah begini
Spoiler for :