CONTOH SOAL PEMOGRAMAN TENTANG ARRAY :
1. # include <iostream.h>
void main () {
int i =80;
cout << "A";
} else if (i > 69) {
} else cout << "B";
} else if (i > 49) {
} else cout << "C";
} else if (i > 39) {
} else cout <<"D";
} else {
cout << "B";
JAWABAN :
B
2. # include <iostream.h>
void main () {
long int a=0, b=0, c=0;
for (int i=10, ; i < 15 ; i++)
a + = i ;
b + = a + i ;
c + = a + b + i ;
}
cout << a << endl ;
cout << b << endl;
cout << c << endl;
JAWABAN :
cara menghitungnya :
i a b c
0 0 0
10 10 20 40
11 21 52 124
12 33 97 266
13 46 156 481
14 60 230 789 ==> jawab : 60,230, 789
3. # include <iostream.h>
int hitung (int i) ;
return i*i ;
}
void main () {
int a=0 ;
for (int i = 3 ; i < 8 ; i++) {
a+ = hitung (i) ;
}
cout <<a ;
JAWABAN :
cara menghitung nya :
a = a + hitung (i)
i hitung (i) a=a+ hitung (i)
3 9 9
4 16 25
5 25 50
6 36 86
7 49 135
jawab : 135
4. #include <iostream.h>
int hitung (int i) {
return (i * 2) +1 ;
void main () {
int b = 0 ;
int c = 0 ;
for (int i=0 ; i < 5 ; i++)
b = c + hitung (b) ;
c + = b ;
}
cout << c ;
JAWABAN :
i a (i) b + a (i) hitung (b + a)(i)
0 1 1 1
1 4 5 3
2 14 19 9
3 48 67 29
4 164 231 97
jawab : 231
5. # include <iostream.h>
int hitung (int i) {
return (i * 2) + 1 ;
}
void main () {
int a [3] = {23,45,67}
int b = 0
for (int i = 0 ; i < 3 ; i++) {
b + hitung (b + a [i])
JAWABAN :
diket :
a[0] = 23 a[1] = 45 a [2] = 67
jadi :
i b a (i) b + a (i) hitung (b + a ) (i)
0 47 23 23 47
1 232 45 92 185
2 831 67 299 599
jawab : 831, 23
sekian semoga membantu.
0 comments:
Post a Comment