Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

10.5 Nested loop 6.3 & 7.3 NESTED LOOP 255.

Presentasi serupa


Presentasi berjudul: "10.5 Nested loop 6.3 & 7.3 NESTED LOOP 255."— Transcript presentasi:

1 10.5 Nested loop 6.3 & 7.3 NESTED LOOP 255

2 10.5 NESTED LOOP 255

3 ? - Pendahuluan #include<stdio.h> main() { int J;
for ( J=1; J<=5; J++) { - } J 1 2 3 4 5 6 - Loop Berapa kali loop dikerjakan ? 255

4 Pendahuluan int J; for ( J=1; J<=5; J++) { - } - J<=5 J<=5
false J<=5 true - true - - false J++ J++ Atau J=1 J++1 - J<=5 true false

5 #include<stdio.h> main() { int J; J = 1; while ( J<=5 ) { -
Pendahuluan J<=5 J=1 J=J+1 false true - #include<stdio.h> main() { int J; J = 1; while ( J<=5 ) { - J++; } Atau J<=5 false true J=1 J=J+1 - - Loop

6 Pendahuluan #include<stdio.h> main() { int J; for ( J=1; J<=5; J++) { - } #include<stdio.h> main() { int J; J = 1; while ( J<=5 ) { - J++; }

7 #include<stdio.h> main() { int J; for ( J=1; J<=5; J++) {
Pendahuluan #include<stdio.h> main() { int J; for ( J=1; J<=5; J++) { printf(“Jakarta”); } #include<stdio.h> main() { int J; J=1; while ( J<=5 ) { printf(“Jakarta”); J++; } Tercetak: JakartaJakartaJakartaJakartaJakarta

8 Pendahuluan #include<stdio.h> main() { int J; J = 1; while ( J<=5 ) { printf(“\nJakarta”); J++; } #include<stdio.h> main() { int J; for ( J=1; J<=5; J++) { printf(“\nJakarta”); } Tercetak: Jakarta Tercetak: Jakarta

9 Pendahuluan #include<stdio.h> main() { int J; J = 1; while ( J<=5 ) { printf(“\n%i”, J ); J++; } #include<stdio.h> main() { int J; for ( J=1; J<=5; J++) { printf(“\n%i”, J ); } Tercetak : 1 2 3 4 5 Tercetak : 1 2 3 4 5

10 6.3 Nested Loop dengan for( )
Pemahaman Nested Loop #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } (A) for ( J=1; J<=5; J++) { } - for ( J=1; J<=5; J++) { } (B) -

11 printf(“\nJakarta”) printf(“\nJakarta”)
for ( J=1; J<=5; J++) { } #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } printf(“\nJakarta”) for ( J=1; J<=5; J++) { } Tercetak : Jakarta printf(“\nJakarta”) Tercetak : Jakarta - 15 kali 258

12

13 ? ? #include<stdio.h> main() { int J; for(J=1; J<=5; J++) {
printf(“\n%i”, J); } ? 6.15 Tercetak : ? 258

14 ? #include<stdio.h> main() {int J; for(J=1; J<=5; J++) {
6.15 ? #include<stdio.h> main() {int J; for(J=1; J<=5; J++) { printf(“\n%i”, J); } Tercetak : 1 2 3 4 5

15

16 ? ? #include<stdio.h> void main() {int I, J;
for(I=1; I<=3; I++) {for(J=1; J<=5; J++) { printf(“\n%i”,J); } 6.15 disebut : Loop 3 x 5 ? Tercetak :

17 #include<stdio.h> void main() {int I, J; for(I=1; I<=3; I++)
{for(J=1; J<=5; J++) { printf(“\n%i”,J); } I J 1 2 3 4 5 Tercetak : 1 2 3 4 5

18

19

20 6.15 I J I J 1 2 3 1 2 3 4 5 1 2 3 1 2 3 4 5 258

21

22 #include<stdio.h> void main() {int I, J; I=1; while( I<=3 )
while ( J<=5 ) { printf(“\n%i”, J); J++; } I++; Tercetak : I J 1 2 3 4 5 1 2 3 4 5 258

23 #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) {
Perhatikan kembali Nested Loop sebelumnya sebagai berikut ini : I=1 #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } I<=3 false true J=1 for ( J=1; J<=5; J++) { } J<=5 false Outer loop true Outer loop - Inner loop Inner loop J++ I++ 258 keluar

24 I=1 I<=3 J=1 J<=5 J++ I++
#include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } I=1 I<=3 true J=1 for ( J=1; J<=5; J++) { } false J<=5 true - Outer loop Inner loop false J++ I++ 258 keluar

25 printf(“\nJakarta”);
Contoh Penggunaan Nested Loop #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } Tercetak : Jakarta for ( J=1; J<=5; J++) { } printf(“\nJakarta”); 258

26 #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) {
} Tercetak : 1 2 3 4 5 for ( J=1; J<=5; J++) { } printf(“\n%i”, J); 258

27 printf(“%3i”, J ); printf(“%3i”, J );
#include<stdio.h> main() { int I, J; I=1; while( I<=3) { I++; } #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { } J=1; while ( J<=5) { J++; } for ( J=1; J<=5; J++) { } printf(“%3i”, J ); printf(“%3i”, J ); Tercetak : 258

28 ? ? #include<stdio.h> main() { int I, J;
for ( I=1; I<=3; I++) { } for ( J=1; J<=5; J++) printf(“%3i”, J ); #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { printf(“\n”); } for ( J=1; J<=5; J++) { } printf(“%3i”, J ); Tercetak : ? ? Tercetak : Tercetak : 258

29 #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) {
printf(“\n”); } 1 2 3 1 2 3 4 5 for ( J=1; J<=5; J++) { } printf(“%3i”, J ); Tercetak : Loop 3 x 5 Hal: 257 258

30

31 ? #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++)
for(J = 1; J<=5; J++) { printf(“%3i”, I ); } printf(“\n”); } nyetak I ? ? Tercetak : 259

32 #include<stdio.h> void main() { int I, J;
for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, I ); } printf(“\n”); } 1 2 3 1 2 3 4 5 Tercetak : Hal: 258 259

33 ? ? #include<stdio.h> main() { int I, J;
for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, I+J ); } printf(“\n”); } ? Tercetak : 259

34 I J I+J #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, I+J ); } printf(“\n”); } 1 2 3 1 2 3 4 5 2 3 4 5 6 7 8 Tercetak :

35 Susun program untuk mencetak nilai-
nilai ( 1- 15) sehingga tercetak sebagai berikut : a. b. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 c. Hal. 266 Soal-04. g d. Hal. 266 Soal-04.k 266

36 a. { int I; for ( I=1; I<=15; I++) { printf(“%3i”, I ); } }
{ int I; for ( I=1; I<=15; I++) { printf(“%3i”, I ); } } I N 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 atau : { int I,N; N=1; for ( I=1; I<=15; I++) { printf(“%3i”, N ); N++; }

37 b. { int I; for ( I=1; I<=15; I++) { printf(“\n%i”, I ); } }
2 3 4 5 6 7 8 9 10 11 12 13 14 15 { int I; for ( I=1; I<=15; I++) { printf(“\n%i”, I ); } } I N 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 atau : { int I,N; N=1; for ( I=1; I<=15; I++) { printf(“\n%i”, N ); N++; }

38 ? a. Dengan menggunakan Nested Loop I J Tercetak
1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) printf(“%3i”, ………………. ); } ?

39 a. #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++)
Menggunakan Nested Loop I J (I-1)*5+J 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) printf(“%3i”, ( I-1 )*5 + J ); }

40 b. Menggunakan Nested Loop I J 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2
#include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) printf(“\n%i”, ( I-1 )*5 + J ); }

41

42 c. I J (I-1)*5+J 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Dengan Nested Loop #include<stdio.h> main() { int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, (I-1)*5+J ); } printf(“\n”); }

43 c. I J N 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Dengan Nested Loop #include<stdio.h> main() { int I, J, N; N = 1; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, N ); N++; } printf(“\n”); Hal : 259

44 c. int I, J, N; N = 1; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, N ); N++; } printf(“\n”); int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”,(I-1)*5+J ); } printf(“\n”); } Hal : 259

45 #include<stdio.h>
main() { int I, X; X = 0; for ( I=1; I<=15; I++) { printf(“%3i”, I ); X++; if (X=5) { printf(“\n”); } I X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 Tercetak :

46 #include<stdio.h>
main() { int I; for ( I=1; I<=15; I++) { printf(“%3i”, I ); if (I%5 == 0) printf(“\n”); } I I%5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 Tercetak :

47

48 c. int I, J, N; N = 1; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”, N ); N++; } printf(“\n”); int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=5; J++) { printf(“%3i”,(I-1)*5+J ); } printf(“\n”); } d. SOAL : Susun program untuk mencetak :

49 d. I 1 2 3 4 5 J 1 2 3 (I-1)*3 + J 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int I, J; for ( I=1; I<=5; I++) { for(J = 1; J<=3; J++) { printf(“%3i”,(I-1)*3+J ); } printf(“\n”); } Loop 5 x 3

50 d. I 1 2 3 4 5 J 1 2 3 N 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int I, J, N; N = 1; for ( I=1; I<=5; I++) { for(J = 1; J<=3; J++) { printf(“%3i”,N ); N++; } printf(“\n”);

51 d. int I, J, N; N = 1; for ( I=1; I<=5; I++) { for(J = 1; J<=3; J++) { printf(“%3i”, N ); N++; } printf(“\n”); int I, J; for ( I=1; I<=5; I++) { for(J = 1; J<=3; J++) { printf(“%3i”,(I-1)*3+J ); } printf(“\n”); }

52

53 ? ? #include<stdio.h> main() { int I, J;
for ( I=1; I<=3; I++) { for(J=1; J<=5; J++) printf(“\n%i”, J); } ? ? Tercetak : disebut : Loop 3 x 5

54 #include<stdio.h>
main() { int I, J; for ( I=1; I<=3; I++) { for(J=1; J<=5; J++) printf(“\n%i”, J); } Tercetak : I J 1 2 3 4 5 1 2 3 4 5

55 I J I J 1 2 3 1 2 3 4 5 1 2 3 1 2 3 4 5

56

57 ? ? #include<stdio.h> main() { int I, J;
for ( I=1; I<=3; I++) { for(J=I; J<=5; J++) printf(“\n%i”, J); } ? ? Tercetak : disebut : Loop 3 x 5

58 #include<stdio.h>
main() { int I, J; for ( I=1; I<=3; I++) { for(J=I; J<=5; J++) printf(“\n%i”, J); } Tercetak : I J 1 2 3 4 5 1 2 3 1 2 3 4 5

59 a. b. SOAL : Apa yang tercetak oleh program berikut ini : int I, J;
for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { printf(“%3i”, J ); } printf(“\n”); } int I, J; for ( I=1; I<=3; I++) { for(J = 1; J<=I; J++) { printf(“%3i”, J ); } printf(“\n”); } Tercetak : ? Tercetak : ?

60 a. 1 2 3 4 5 2 3 4 5 3 4 5 int I, J; for ( I=1; I<=3; I++) {
for(J = I; J<=5; J++) { printf(“%3i”, J ); } printf(“\n”); } I 1 2 3 J 1 2 3 4 5 I 1 2 3 J 1 2 3 4 5 Tercetak : Hal : 258

61 b. 1 1 2 1 2 3 int I, J; for ( I=1; I<=3; I++) {
for(J = 1; J<=I; J++) { printf(“%3i”, J ); } printf(“\n”); } I 1 2 3 J 1 2 3 Tercetak : 1 1 2

62

63 c. d. SOAL : Apa yang tercetak oleh program berikut ini : int I, J;
for ( I=1; I<=3; I++) { for(J = 1; J<=6-I; J++) { printf(“%3i”, J ); } printf(“\n”); } int I, J; for ( I=1; I<=3; I++) { for(J = I; J<=6-I; J++) { printf(“%3i”, J ); } printf(“\n”); } Tercetak : ? Tercetak : ?

64 c. 1 2 3 4 5 1 2 3 4 1 2 3 int I, J; I J for ( I=1; I<=3; I++) 1 1
{ for(J = 1; J<=6-I; J++) { printf(“%3i”, J ); } printf(“\n”); } I 1 2 3 J 1 2 3 4 5 Tercetak :

65 d. 1 2 3 4 5 2 3 4 3 I J int I, J; 1 1 for ( I=1; I<=3; I++) 2 { 3
for(J = I; J<=6-I; J++) { printf(“%3i”, J ); } printf(“\n”); } Tercetak : 3

66

67 ? ? #include<stdio.h> main() { int I, J; char C = ‘A’;
for ( I=1; I<=3; I++) { for(J=1; J<=5; J++) printf(“%c”, C); C++; } ? ? Tercetak : disebut : Loop 3 x 5

68 { int I, J; char C = ‘A’; for ( I=1; I<=3; I++) { for(J=1; J<=5; J++) printf(“ %c”, C); C++; } I J 1 2 3 4 5 Tercetak : A B C D E F G H I J K L M N O

69 I J I J 1 2 3 1 2 3 4 5 1 2 3 1 2 3 4 5

70

71 1. int A = 25; printf(“%i”, A+2 ); 27 3. int A = 25; printf(“%i”, A++ ); 25 Nilai A tidak berubah 25 * Cetak nilai A * A ditambah 1 26 A A 2. int A = 25; printf(“%i”, A=A+2 ); 27 4. int A = 25; printf(“%i”, ++A ); 26 27 * A ditambah 2 * Cetak nilai A 26 * A ditambah 1 * Cetak nilai A A A

72 SOAL : Susun program untuk mencetak nilai 1-15, sehingga tercetak sebagai berikut : a. 1 2 3 b. 13 14 15 c. 1 2 3 d. 13 14 15

73 a. b. SOAL : Apa yang tercetak bila program berikut ini dijalankan :
#include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; printf(“%3i”, T ); } printf(“\n”); #include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; } printf(“%3i”, T ); printf(“\n”);

74 a. SOAL : Apa yang tercetak bila program berikut ini dijalankan :
#include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; } printf(“%3i”, T );

75 a. b. SOAL : Apa yang tercetak bila program berikut ini dijalankan :
#include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; printf(“%3i”, T ); } printf(“\n”); #include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; } printf(“%3i”, T ); printf(“\n”);

76 c. #include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; } printf(“%3i”, T );

77

78 a. #include<stdio.h> main() { int I, J, T; T = 0;
for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; printf(“%4i”, T ); } printf(“\n”); I 1 2 3 J 1 2 3 4 5 T=0 1 3 6 10 15 17 20 24 29 32 36 41 Tercetak :

79

80 b. #include<stdio.h> main() { int I, J, T; T = 0;
for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; } printf(“%3i”, T ); printf(“\n”); I 1 2 3 J 1 2 3 4 5 T=0 1 3 6 10 15 17 20 24 29 32 36 41 Tercetak : 15 29 41

81

82 I 1 2 3 J 1 2 3 4 5 T=0 1 3 6 10 15 17 20 24 29 32 36 41 c. #include<stdio.h> main() { int I, J, T; T = 0; for ( I=1; I<=3; I++) { for(J = I; J<=5; J++) { T = T + J; } printf(“%3i”, T ); Tercetak : 41

83


Download ppt "10.5 Nested loop 6.3 & 7.3 NESTED LOOP 255."

Presentasi serupa


Iklan oleh Google