6A.
1.
#include <cstdlib>
#include <iostream>
using namespace std;
void bil(int a)
{
if(a%2!=0)
cout<<"bilangan ganjil"<<endl;
else
cout<<"bilangan genap"<<endl;
}
int main(int argc, char *argv[])
{
int b;
cout<<"|============================|\n";
cout<<"| Menentukan Bilangan Ganjil |\n";
cout<<"| Atau Genap |\n";
cout<<"|============================|\n";
cout<<"masukkan sebuah bilangan : ";cin>>b;
bil(b);
system("pause");
return 0;
}
2.
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
void luas(int p,int l){
int hasil;
hasil=p*l;
cout<<"Luas Persegi Panjang : "<<hasil<<endl;
}
int main(int argc, char *argv[])
{
int a,b;
cout<<"|========================|\n";
cout<<"| Mencari Luas Persegi |\n";
cout<<"| Panjang |\n";
cout<<"|========================|\n";
cout<<"Masukkan Panjang : ";cin>>a;
cout<<"Masukkan Lebar \t: ";cin>>b;
luas(a,b);
system("pause");
return 0;
}
3.
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
void kel(int p,int l){
int hasil;
hasil=2*(p+l);
cout<<"Keliling persegi panjang : "<<hasil<<endl;
}
int main(int argc, char *argv[])
{
int a,b;
cout<<"|==========================|\n";
cout<<"| Mencari Keliling Persegi |\n";
cout<<"| Panjang |\n";
cout<<"|==========================|\n";
cout<<"Masukkan lebar persegi \t: ";cin>>a;
cout<<"Masukkan panjang persegi : ";cin>>b;
kel(a,b);
system("pause");
return 0;
}
4.
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
void luas(int r){
int hasil,phi;
phi=3,14;
hasil=phi*r*r;
cout<<"Hasil luas lingkaran : "<<hasil<<endl;
}
int main(int argc, char *argv[])
{
int r;
cout<<"|=========================|\n";
cout<<"| Program Menghitung Luas |\n";
cout<<"| Lingkaran |\n";
cout<<"|=========================|\n";
cout<<"Masukkan jari-jari : ";cin>>r;
luas(r);
system("pause");
return 0;
}
5.
#include <cstdlib>
#include <iostream>
using namespace std;
void kel(int r){
int hasil,phi;
phi=3,14;
hasil=2*phi*r;
cout<<"Keliling lingkaran : "<<hasil<<endl;
}
int main(int argc, char *argv[])
{
int r;
cout<<"|=============================|\n";
cout<<"| Program Menghitung Keliling |\n";
cout<<"| Lingkaran |\n";
cout<<"|=============================|\n";
cout<<"Masukkan jari-jari : ";cin>>r;
kel(r);
system("pause");
return 0;
}
6B.
1.
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void tukar (int*a,int*b)
{ int temp;
temp=*a;
*a=*b;
*b=temp;
}
int main(int argc, char *argv[]) {
int a=100,b=50;
cout<<"Sebelum Tukar\n";
cout<<"Isi Nilai 1 = "<<a<<endl;
cout<<"Isi Nilai 2 = "<<b<<endl;
tukar(&a,&b);
cout<<"Sesudah Tukar\n";
cout<<"Isi Nilai 1 = "<<a<<endl;
cout<<"Isi Nilai 2 = "<<b<<endl;
return 0;
}
2.
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int maksimum2(int a, int b)
{
if(a>b) return (a);
else return(b);
}
int main(int argc, char *argv[]) {
int x,y;
cout<<"Masukan dua integer\n";
cout<<"Bilangan Pertama : ";
cin>>x;
cout<<"Bilangan Kedua : ";
cin>>y;
cout<<"Nilai Terbesar : "<<maksimum2(x,y);
return 0;
}
3.
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
long facktorial (int n)
{
if((n==0)||(n==1)) return (1);
else return (n*facktorial(n-1));
}
int main(int argc, char *argv[]) {
int n;
long hasil;
cout<<"Masukan Integer n : ";
cin>>n;
hasil=facktorial(n);
cout<<"Nilai"<<n<<"!="<<hasil;
return 0;
}
Latihan
6.
#include <iostream>
#include <string>
using namespace std;
int main()
{
float L,t,a;
cout<<"Masukan Nilai Alas : "<< endl;
cin >> a;
cout<<"Masukan Nilai Tinggi : "<<endl;
cin >> t;
L = (a*t)/2;
cout << "Nilai Alas : "<<a << endl;
cout << "Nilai Tinggi : "<<t << endl;
cout << "Luas :"<<L << endl;
return 0;
}
7.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string raptor_prompt_variable_zzyz;
float keliling,a,b,c;
cout << "Angka Pertama : ";
cin >> a;
cout <<"Angka Kedua : ";
cin >> b;
cout << "Angka Ketiga : ";
cin >> c;
keliling =a+b+c;
cout << "Keliling "<< keliling << endl;
return 0;
}
8.
#include <iostream>
#include <string>
using namespace std;
int main()
{
float l,t,a;
cout<<"Masukan Nilai Alas : "<<endl;
cin >> a;
cout<<"Masukan Nilai Luas : "<< endl;
cin >> l;
t =2*l-a;
cout << "Nilai Alas : "<<a << endl;
cout << "Nilai Luas :"<<l << endl;
cout << "Tinggi : "<<t << endl;
return 0;
}
9.
#include <cstdlib>
#include <iostream>
using namespace std;
int faktorial (int n)
{
int fak;
if (n<=1)
{
fak=1;
}
else
{
fak=n*faktorial(n-1);
}
return (fak);
}
int main(int argc, char *argv[])
{
int n,r, kombinasi;
cout<<" Program Menghitung Kombinasi"<<endl;
cout<<" \n Masukkan Nilai n : "; cin>>n;
cout<<" \n Masukkan Nilai r : "; cin>>r;
kombinasi=faktorial(n)/(faktorial(r)*faktorial(n-r));
cout<<" \n Kombinasinya adalah: "<<kombinasi<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
10.
#include <iostream>
#include <cstdlib>
using namespace std;
class permutasi{
private:
int a,b,c,n,r,hasil;
public:
void masukan();
void proses();
void keluaran();
};
void permutasi::masukan(){
cout<<"Program Menghitung Permutasi"<<endl<<endl;
cout<<"masukan n : ";
cin>>n;
cout<<"masukan r : ";
cin>>r;
if(n<r){cout<<"masukan salah n harus lebih besar dari r, silahkan coba kembali. "<<endl;
masukan();}
else{proses();}
}
void permutasi::proses(){
a=1;
for(int i=1;i<=n;i++){
a=a*i;}
b=n-r;
c=1;
for(int i=1;i<=b;i++){
c=c*i;
}
hasil=a/c;keluaran();
}
void permutasi::keluaran(){
cout<<"hasil permutasi adalah : "<<hasil<<endl;
}
int main(int argc, char *argv[])
{
permutasi a;
a.masukan();
system("PAUSE");
return EXIT_SUCCESS;
}
Minggu, 17 April 2016
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar