- Dapatkan link
- X
- Aplikasi Lainnya
Program Hitung Luas Persegi
Program Konversi Jam ke Menit dan Detik
Program Mengetahui Bilangan Genap atau Ganjil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// Kamus | |
// Fungsi untuk menghitung luas persegi | |
float luasPersegi(int p,int l){ | |
int hasil; //definisi | |
hasil = p*l; | |
return hasil; | |
} | |
// Prosedur untuk menghitung luas persegi | |
void Lpersegi(int p, int l){ | |
cout << p*l << endl; | |
} | |
// Kamus Global | |
int jumlah(int a,int b); // parameter formal | |
int main(){ | |
cout << "Hasil fungsi persegi (4,5): " << luasPersegi(4,5) << endl; | |
cout << "Hasil prosedur persegi(3,3): " ; | |
Lpersegi(3,3); | |
cout << "Hasil fungsi penjumlahan (5,8): " << jumlah(5,8) << endl; | |
} | |
//Fungsi untuk menjumlahkan 2 bilangan | |
int jumlah (int a, int b){ | |
return a+b; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int jamKeDetik(int jam, int menit, int detik){ | |
int hasilDetik; | |
hasilDetik = (jam*3600)+(menit*3600)+(detik); | |
return hasilDetik; | |
} | |
int durasiWaktu(int detikAwal, int detikAkhir){ | |
int durasi; | |
durasi = detikAkhir - detikAwal; | |
return durasi; | |
} | |
void waktu1(){ | |
cout << "Waktu 1" << endl; | |
cout << "Input jam: " ; cin >> jam1; | |
cout << "Input menit: " ; cin >> menit1; | |
cout << "Input detik: " ; cin >> detik1; | |
hasilAwal = jamKeDetik(jam1,menit1,detik1); | |
cout << "Hasil konversi ke detik: " << hasilAwal << endl; | |
cout << endl; | |
} | |
void waktu2(){ | |
cout << "Waktu 2" << endl; | |
cout << "Input jam: " ; cin >> jam2; | |
cout << "Input menit: " ; cin >> menit2; | |
cout << "Input detik: " ; cin >> detik2; | |
hasilAkhir = jamKeDetik(jam2,menit2,detik2); | |
cout << "Hasil konversi ke detik: " << hasilAkhir << endl; | |
} | |
void durasiWaktu12(){ | |
hasilDurasi = durasiWaktu(hasilAwal,hasilAkhir); | |
cout << "Hasil durasi waktu 1 dan 2: " << hasilDurasi << endl; | |
} | |
int jam1,menit1,detik1,hasilAwal; | |
int jam2,menit2,detik2,hasilAkhir; | |
int hasilDurasi; | |
int main(){ | |
int hasilDurasiJam = hasilDurasi/3600; | |
hasilDurasi = hasilDurasi-(3600*hasilDurasiJam); | |
int hasilDurasiMenit = hasilDurasi/60; | |
int hasilDurasiDetik = hasilDurasi-(60*hasilDurasiMenit); | |
cout << "Jam: " << hasilDurasiJam << endl; | |
cout << "Menit: " << hasilDurasiMenit << endl; | |
cout << "Detik: " << hasilDurasiDetik << endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// Kamus Global | |
int i,y; //untuk looping | |
int x[5]; //array | |
void genapkah(int x); // menetukan genap | |
void cetakGenap(int a[]); // menetukan isi array yg genap | |
void inputArr(); // untuk menginput array | |
int main(){ | |
genapkah(7); | |
inputArr(); | |
cetakGenap(x); | |
} | |
void genapkah(int x){ | |
if(x%2==0){ | |
cout << x << " adalah bilangan genap: " << endl; | |
} | |
else if(x%2==1){ | |
cout << x << " adalah bilangan ganjil " << endl; | |
} | |
else{ | |
cout << x << " bukan genap maupun ganjil" << endl; | |
} | |
} | |
void inputArr(){ | |
i = 0; | |
do{ | |
cout << "Masukkan bilangan ke-" << i+1 << " : " ; | |
cin >> x[i]; | |
i = i+1; | |
} while(i<5); | |
} | |
void cetakGenap(int a[]){ | |
cout << "Bilangan genap: " ; | |
i=0; | |
while(i<5){ | |
if(a[i]%2==0){ | |
cout << a[i] << " "; | |
} | |
i++; | |
} | |
} |
- Dapatkan link
- X
- Aplikasi Lainnya
Komentar
Posting Komentar