BAB 7
ARRAY SATU DIMENSI
ARRAY SATU DIMENSI
Latihan
1. Buatlah algoritma dan subprogram yang cara kerjanya seperti function pos di atas.
1. Buatlah algoritma dan subprogram yang cara kerjanya seperti function pos di atas.
ALGORITMA
Deklarasi Subprogram
c,i,j,kali,proses,masuk,hasil=integer
Deskripsi
Void masuk(c[20],b[20])
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Write(“Vaktor A”)
Write(“Vaktor B”)
Void proses(c[20],b[20])
Write(“Vaktor A”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Write(b)
Write(“Vaktor B”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Write(c)
Write(“Vaktor C”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Hasil<-b+c
Write(hasil)
Write(“Vaktor Hasil
Kali”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Kali<-b*hasil
Write(Kali)
Write(“Banyak Elemen”)
Int main()
Write(“Menghitung
Vaktor”)
Masuk(b,c)
Proses(b,c,hasil,kali)
Return 0;
PROGRAM
#include <iostream>
#include <windows.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void masuk(int c[20],int b[20]){
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
cout<<"Vaktor A "<<i<<","<<j<<" =";cin>>b[i,j];
cout<<"Vaktor B "<<i<<","<<j<<" =";cin>>c[i,j];
}
}
system("cls");
}
void proses(int b[20],int c[20],int hasil[20],int kali[20]){
cout<<"Vaktor A"<<endl;
for(int i=1;i<=2;i++){
for(int j=1;j<=3;j++){
cout<<b[i,j]<<" ";
}
}
cout<<"\n\nVaktor B"<<endl;
for(int i=1;i<=2;i++){
for(int j=1;j<=3;j++){
cout<<c[i,j]<<" ";
}
}
cout<<"\n\nVektor C"<<endl;
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
hasil[i,j]=b[i,j]+c[i,j];
cout<<hasil[i,j]<<" ";
}
}
cout<<"\n\nVaktor Hasil Kali"<<endl;
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
kali[i,j]=b[i,j]*hasil[i,j];
cout<<kali[i,j]<<" ";
}
}
cout<<"\n\nBanyak Elemen ="<<12;
}
int main(int argc, char** argv) {
int hasil[20];
int kali[20];
int b[20];
int c[20];
cout<<"Menghitung faktor"<<endl;
masuk(b,c);
proses(b,c,hasil,kali);
return 0;
}
#include <windows.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void masuk(int c[20],int b[20]){
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
cout<<"Vaktor A "<<i<<","<<j<<" =";cin>>b[i,j];
cout<<"Vaktor B "<<i<<","<<j<<" =";cin>>c[i,j];
}
}
system("cls");
}
void proses(int b[20],int c[20],int hasil[20],int kali[20]){
cout<<"Vaktor A"<<endl;
for(int i=1;i<=2;i++){
for(int j=1;j<=3;j++){
cout<<b[i,j]<<" ";
}
}
cout<<"\n\nVaktor B"<<endl;
for(int i=1;i<=2;i++){
for(int j=1;j<=3;j++){
cout<<c[i,j]<<" ";
}
}
cout<<"\n\nVektor C"<<endl;
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
hasil[i,j]=b[i,j]+c[i,j];
cout<<hasil[i,j]<<" ";
}
}
cout<<"\n\nVaktor Hasil Kali"<<endl;
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
kali[i,j]=b[i,j]*hasil[i,j];
cout<<kali[i,j]<<" ";
}
}
cout<<"\n\nBanyak Elemen ="<<12;
}
int main(int argc, char** argv) {
int hasil[20];
int kali[20];
int b[20];
int c[20];
cout<<"Menghitung faktor"<<endl;
masuk(b,c);
proses(b,c,hasil,kali);
return 0;
}
2. Buatlah algoritma dan function dalam bahasa C untuk menggantikan strlen, yaitu
mengetahui panjang suatu string
3. Buatlah algoritma dan function untuk mengubah huruf besar menjadi huruf kecil,
kemudian buatlah function untuk mengubah string menjadi string yang hurufnya huruf
besar semua.
0 comments:
Posting Komentar