-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_basis_ganjilgenap.cpp
More file actions
62 lines (57 loc) · 1.76 KB
/
Copy patharray_basis_ganjilgenap.cpp
File metadata and controls
62 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <conio.h>
int jml_data;
using namespace std;
void first(int arr[]){ //void 1
int hasil;
for(int i=0;i<jml_data;i++){
cout << "masukkan larik data ke-["<<i<<"] = ";cin>>arr[i];
}
}
void second(int arr[]){ //void 2
for(int i=0;i<jml_data;i++){
if (i%2 == 0)
cout << "data array ke-["<<i<<"] = "<<arr[i]<< "-> genap"<<endl;
else {
cout << "data array ke-["<<i<<"] = "<<arr[i]<< "-> ganjil"<<endl;
}
}
}
void three(int arr[]){ //void 3
int total=0;
for(int i=jml_data-1;i>=0;i--){
if(i%2==0){
if (i==0){
cout << "genap" <<arr[i]<< " = ";}
else{
cout <<arr[i]<< " + ";
total=total+arr[i];
}
cout<<total<<endl;}
else{
if (i==0){
cout << "ganjil" <<arr[i]<< " = ";}
else{
cout <<arr[i]<< " + ";
total=total+arr[i];
}
cout<<total<<endl;}
}}
int main (){
int p; int data[100];
do{
system("cls"); //untuk membersihkan layar (system("cls")) setelah proses selesai
cout<< "1. masuk array" <<endl; //pemilihan data
cout<< "2. display array" <<endl;
cout<< "3. hitung array" <<endl;
cout<< "masukkan pilihan :";cin>>p ;
switch(p){
case 1 : cout<< "masukkan jumlah data ";cin>>jml_data; //untuk di arahkan ke void 1
first(data);break;
case 2 : second(data);break; //untuk di arahkan ke void 2
case 3 : three(data);break; //untuk di arahkan ke void 3
}
getch(); //teman dari system("cls") untuk membatasi layar yang ingin dibersihkan apabila prosesnyaa telah selesai
}while (p!=4);
return 0;
}