Pertemuan Keempat kali ini membahas Array.
1. Array [Input & Output]
#include <iostream>
using namespace std;
class Arrq{
private:
int arr[9];
int i;
public:
void input(int i,int b){
if (i<b){
cout<<"Masukkan Array ";
cin>>arr[i];
input(i+1,b);
}
}
void output(int i,int b){
//for (int i=0;i<9;i++){
if (i<b){
cout<<arr[i]<<" ";
cout<<endl;
output(i+1,b);
}
}
};
int main(int argc, char *argv[]) {
Arrq a;
a.input(0,9);
cout<<endl;
a.output(0,9);
return 0;
}
2. Array [Mengubah baris menjadi kolom]
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int arr[9]={1,2,3,4,5,6,7,8,9,};
int p=0;
cout<<"sebelum di tukar= \n";
for(int b=0;b<3;b++){
for(int h=0;h<3;h++){
cout<<arr[h+p]<<" ";
}cout<<endl;
p=p+3;
}
int q=0;
for (int c=0;c<9;c++){
if (arr [c]%3!=0){
int temp=arr[c];
arr[c]=arr[c+1];
arr[c+1]=temp;
}
}
cout<<"setelah di tukar = \n";
cout<<endl;
for(int i=0;i<3;i++){
for (int a=0;a<3;a++){
cout<<arr[a+q]<<" ";
}cout<<endl;
q=q+3;
}
return 0;
}
Sekian terima kasih pembahasan array kali ini, semoga membantu.
Rabu, 21 Oktober 2015
Pertemuan Minggu [04] Structur Data [29 September 2015]
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar