Catatan: untuk memasukkan text dalam kotak yang telah disediakan silahkan
klik kanan, pilih add text atau edit text, masukkan text.
Soal:
Jawaban:
#include<stdio.h>
#include<stdlib.h>
int main() {
int i, j;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=1;
while(i<=5){
int j=1;
while(j<=i){
printf("%d",i);
j++;
}
printf("\n");
i++;
}
return 0;
}
Screenshot hasil program
Kode program
#include<stdio.h>
3.
#include<stdlib.h>
4.
5.
int
6. main(){
7. int i, hasil=0, max;
8.
9. printf("Masukkan angka :");
10.scanf("%d", &max);
11.
for (i = 0; i <=max; i++)
12.
{
13.
hasil = i + hasil;
14.
}
15.
printf ("\nHasil=%d\n\n", hasil);
16.
17.return 0;
18.
} 19.
Screenshot hasil program
3. Buatlah program yang dapat mencetak pola angka 1 1 2 3 5 8 13 21 sampai
150
Jawaban:
Kode program
#include
4. <stdio.h>
#include
5. <stdlib.h>
int
6. main() {
7. int i, n, t1 = 0, t2 = 1, nextTerm;
8. printf("Enter the number of terms: ");
9. scanf("%d", &n);
10.printf("Fibonacci Series: ");
11.
12.for (i = 1; i <= n; ++i) {
printf("%d, ", t1);
13.
nextTerm = t1 + t2;
14.
t1 = t2;
15.
t2 = nextTerm;
}
16.
17.
return 0;
18.
}
19.
20.