1. Menghitung ganjil dan genap
RAPTOR :
Program CPP :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void genap_ganjil(int bil){
cout<<bil<<" adalah bilangan ";
if(bil%2==0)
cout<<"genap";
else
cout<<"ganjil";
}
int main(int argc, char** argv) {
int bil;
cout<<"masukkan bilangan: "; cin>>bil;
genap_ganjil(bil);
return 0;
}
3. Menghitung keliling persegi panjang
RAPTOR:
Program CPP :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class pp{
private:
int p,l;
public:
void masuk();
tampil();
};
void pp::masuk(){
cout<<"masukkan panjang= ";cin>>p;
cout<<"masukkan lebar = ";cin>>l;
}
pp::tampil(){
cout<<"keliling persegi panjang "<<p<<"x"<<l<<" = "<<2*p+2*l;
}
int main(int argc, char** argv) {
pp persegi;
persegi.masuk();
persegi.tampil();
return 0;
}
5. Menhitung keliling lingkaran
Program CPP :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
float kel_ling(float j){
float phi=3.1415926535897932384626433832795;
return (phi*j*2);
}
int main(int argc, char** argv) {
float j;
cout<<"masukkan jari-jari lingakran= "; cin>>j;
cout<<"keliling lingkaran = "<<kel_ling(j);
return 0;
}
7. Menghitung keliling segitiga
RAPTOR :
Program CPP :
#include <iostream>
#include <math.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
float kel_seg(int l,int t){
float m=sqrt(t*t+(l*l/4));
return (2*m+t);
}
int main(int argc, char** argv) {
int l,t;
cout<<"masukkan lebar= ";cin>>l;
cout<<"masukkan tinggi= ";cin>>t;
cout<<"kelling segitiga = "<<kel_seg(l,t);
return 0;
}
9. Menghitung kombinasi
RAPTOR :
Program CPP :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int fac(int n){
if(n>1) return n*fac(n-1);
}
class kom{
private:
int n,r,hasil;
public:
void masuk(int,int);
hitung();
int tampilkan();
};
void kom::masuk(int en,int er){
n=en;
r=er;
}
kom::hitung(){
hasil=fac(n)/(fac(r)*fac(n-r));
}
int kom::tampilkan(){
return hasil;
}
int main(int argc, char** argv) {
int en,er; kom terserah;
cout<<"perhitungan kombinasi\n";
cout<<"masukkan jumlah objek="; cin>>en;
cout<<"masukkan jumlah rasio="; cin>>er;
terserah.masuk(en,er);
terserah.hitung();
cout<<terserah.tampilkan();
return 0;
}












0 komentar
Posting Komentar