---
# System prepended metadata

title: Pelatihan Al Azhar - Pemrograman Dasar

---

# Pelatihan Al Azhar - Pemrograman Dasar


1. Berapa output program di bawah
```
#include <iostream>
using namespace std;

int x, y;

int main () {
    x = 20; y = 35;
    x = x + y;
    y = x - y;
    x = x - y;
    cout << x << " " << y << endl;
}
```

2. Berapa output program di bawah?
```
#include <iostream>
using namespace std;

int merpati;

int main () {
    merpati = 2018;
    if (merpati % 100 > 20)
        merpati = merpati + 1;
    else
        merpati = merpati + 2;
    cout << merpati + merpati << endl;
}
```

3. Berapakah nilai d di akhir program jika a=6, b=8, c=5?
```
if (a % 3 == 0) {
    if (b > c) c = b + (c*3) / 2;
    else b = c + (b*3) / 2;
} else {
    if (b > c) b = (a / 2) + c;
    else c = (a / 2) + b;
}
d = a + b + c;
```

4. Apa output program di bawah?
```cpp
#include <iostream>
using namespace std;

    int a, b, c;
    a = 12;
    b = 7;
    c = 0;
    while (b > 0) {
        c = c + a;
        b = b - 1;
    }
    cout << c << endl;

}
```

5. Berapa output program di bawah?
```
x = 24;
y = 37;
z = 125;
while(x>0 && y>0 && z>0) {
    x -= 2;
    y -= 3;
    z -= 5;
}
cout << x+y+z << endl;
```

6. Berapa output program di bawah?
```
c = 100;
a = 1;
b = 50;
while (a<=c) do {
    b = b+2;
    a = a+1;
    c = c-1;
}
cout << b << endl;
```

7. Berapa output program di bawah?
```
N = 3971428
result = 1;
while(N > 0) {
    result = result * (N%10);
    N = N / 10;
}
cout << result << endl;
```

8. Berapa output program di bawah?
```
x = 1;
y = 0;
while(x <= 2022) {
    y := y + x;
    x := x + x;
} 
cout << y << endl;
```

9. Berapakah output program di bawah?
```
n = 2022;
p = 0;
while(n > 0) {
    p++;
    if (n%2==0) {
        n = n-3;
    } else {
        n = n-5;
    }
}
cout << p << endl;
```

10. Berapakah nilai res di akhir program jika left=1, right=100?

```
int mid = left;
int res = 0;
while(mid <= right) {
    if (mid%11 == 0) {
        res++;
        mid++;
    } else if (mid%12 == 0) {
        mid++;
    } else {
        if (mid%4 == 0) {
            res++;
        }
        mid++;
    }
}
```

