You are on page 1of 2

Data a = {90 200 115 70 12 15 67 20}

1. nilai terbesar terkecil


#include <iostream.h>
#include <conio.h>
#ifdef__cplusplus
int fmax(int x,int y){
return(x > y ? x : y);
}
int fmin(int x,int y){
return(x < y ? x : y);
}
#endif
main(){
int a[8] = {90, 200, 115, 70, 12, 15, 67, 20};
int i,max,min;
max = a[0];
min = max;
for(i=0; i<=6; i++){
max = fmax(max,a[i+1]);
min = fmin(min,a[i+1]);
}
cout<<max<<endl<<min;
getch();
}
2. bilangan habis di bagi 5
#include <iostream.h>
#include <conio.h>
main(){
int a[8] = {90, 200, 115, 70, 12, 15, 67, 20};
int i;
for(i=0; i<=7; i++){
if(a[i] % 5 == 0)cout<<a[i]<<" ";
}
getch();
}
3. AND OR dari bilangan pertama dgn terakhir, kedua dgn kedua dari terakhir.
#include <iostream.h>
#include <conio.h>
void main(){
int a[8] = {90, 200, 115, 70, 12, 15, 67, 20};
int i,x,y;
for(int i=0; i<=3; i++){
x = a[i] & a[7-i];
y = a[i] | a[7-i];
cout<<a[i]<<" AND "<<a[7-i]<<" = "<<x<<endl;
cout<<a[i]<<" OR "<<a[7-i]<<" = "<<y<<endl<<"----"<<endl;
}
getch();
}
Inputkan data sebanyak 6
4. Tentukan bilangan yg sisa hasil baginya 2 terhadap 4
#include <iostream.h>
#include <conio.h>
main(){

int a[5];
for(int i=0; i<=5; i++){
cout<<"Masukan bilangan ke "<<i+1<<" = ";
cin>>a[i];
}
for(int i=0; i<=5; i++){
if(a[i] % 4 == 2)cout<<a[i]<<" ";
}
getch();
}
5. Buat programnya untuk mnentukan nilai rata2nya
#include <iostream.h>
#include <conio.h>
main(){
int a[5],rata,jml=0,i;
for(i=0; i<=5; i++){
cout<<"Masukan bilangan ke "<<i+1<<" = ";
cin>>a[i];
}
for(i=0; i<=5; i++){
jml = jml + a[i];
}
rata = jml/6;
cout<<rata;
getch();
}

You might also like