Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nested Loop.

Similar presentations


Presentation on theme: "Nested Loop."— Presentation transcript:

1 Nested Loop

2 for (value1=0;value1<5;value1++) for (value2=0;value2<4;value2++)
Cout value1”” value2 TRUE T 1 2 0 2 3 0 3 4 FALSE XXXXXXXX XX TRURE

3 for (int i=1;i<=3;i++)
Cin>>marks Sum=sum+marks Average=sum/3 Do you want to repeat while (ans=='Y' || ans=='y'); 1 T 10 10=0+10 2 4 14=10+4 3 8 22=14+8 FALSE 7=22/3 Y TRUE

4 while(num!=sentinel) for (x=1;x<=12;x=x+1)
enter a number while(num!=sentinel) x x<=12 total = x * num cout x * num = total num!=-1 7 TRUE 1 T 7=1x7 1 * 7 = 7 2 t 14=2 x 7 2 * 7 =14 12 84=12X7 12 * 7 =84 13 FALSE 5 7=1x5 1 * 5 = 5 14=2 x 5 2 * 5 =10 84=12X5 12 * 5 =60 -1 false

5 - Operation Initialization – set nilai pertama
Evaluation – check T atau F Updating – increase atau decrease

6 Short Answer Question -Operation
- 3 (a) page 119 Initialization – respond = ‘Y’; Evaluation – while (respond==‘Y’); Updating – cin>>respond;

7 Short Answer Question -Operation
- 3 (b) page 120 Initialization – x=1 Evaluation – while (x<=100) Updating – x++

8 Short Answer Question - Operation
- 3 (c) page 120 Initialization – a=100 Evaluation – a<0 Updating – a+=10; // a=a+10;

9 Question 10 (a) – trace output
number Number!=-999 Sum=sum+number TRUE 100 100= 25 125=100+25 70 195=125+70 56 241=195+56 -999 FALSE Answer = 241

10 cout><<i<<“ “
Question 10(b) Do (i) = 1 i=i*4 cout><<i<<“ “ While (i<=100) 1 4= i*4 4 TRUE 16= 4 * 4 16 64= 16 * 4 64 256=64*4 256 FALSE Answer :

11 Question 10(c) X = 15 while (x>5) If(x==9) x-- Cout x “ ” 15 T
FALSE 14 13 12 11 10 9 TRUE - break Answer :

12 Question 10 (d) for (x=0;x<=55;x=x+10
cout <<“hello World !” x=x+10 TRUE Hello World! 10=0+10 10 T 20=10+10 20 30=20+10 30 40=30+10 40 50=40+10 50 60=50+10 60 FALSE Thank you

13 Question 10 (e) 6 1 A = 2 B = 55 while a<6 b=b%2 a=a+2
Cout<<a “ “ b 2 55 TRUE 1=55%2 4=2+2 4 1 1=1%2 6=4+2 6 FALSE 6 1

14 cout<<g<<endl;
Question f & g page 121 g While (g!=-1) i++ cin>>g; cout<<g<<endl; 100 TRUE 1 250 2 342 3 125 4 210 5 280 6 -1 FALSE

15 Question 10 (h) for (k=10;k>5;k=k-2)
cout k k=k-2 10 TRUE 8=10-2 8 6=8-2 6 4=6-2 4 FALSE

16 Question 10 (j) for (i=1;i<=3;i++) for (j=1;j<=4;j++)
cout<<“$” cout<<\n 1 T $ 2 3 4 5 F TRUE

17 for (i=1;i<=3;i++) for (j=1;j<=4;j++)
x x<4 y y<2 1 2 3 4 FALSE TRUE $

18 Objektif 6 : K=5 K Cin>>value K++ K<0 5 10 6 false

19 Objektif 8 J=30 k k=<30 cout k k=k*2 1 TRUE 2=1*2 2 4=2*2 4 T 8=4*2
16=8*2 16 32=16*2 32 FALSE


Download ppt "Nested Loop."

Similar presentations


Ads by Google