include stdio h mainvoid int i 0 int

  • Slides: 7
Download presentation
#include <stdio. h> main(void) { int i = 0; int j = 0; /*

#include <stdio. h> main(void) { int i = 0; int j = 0; /* print out i and j as the while loops */ while(i<2) { j = 0; while(j<2){ printf("i= %d, j= %dn", i, j); j = j + 1; } i = i + 1; } } 1. i= 0, j= 0 i= 0, j= 1 i= 1, j= 0 i= 1, j= 1 2. i= 0, j= 0 i= 1, j= 1 3. i= 0, j= 0 i= 1, j= 0 4. i= 0, j= 0 i= 1, j= 1

#include <stdio. h> main(void) { int i = 0; int j = 0; float

#include <stdio. h> main(void) { int i = 0; int j = 0; float num 1; /* multiply ½ with num 1*/ num 1 = 16. 0; while(i<2) { j = 0; while(j<2){ num 1 = 1. /2. *num 1; j = j + 1; } i = i + 1; } printf(“num 1 = %f”, num 1); } 1. num 1 = 0. 000000 2. num 1 = 10. 0 3. num 1 = 1. 000000

#include <stdio. h> main(void) { int i = 0; int j = 0; float

#include <stdio. h> main(void) { int i = 0; int j = 0; float num 1; /* multiply ½ with num 1*/ num 1 = 16. 0; while(i<2) { j = 0; while(j<2){ num 1 = 1. /2. *num 1; j = j + 1; } i = i + 1; } printf(“num 1 = %. 2 f”, num 1); } 1. num 1 = 0. 00 2. num 1 = 1. 000000 3. num 1 = 1. 00

#include <stdio. h> main(void) { int i = 0; int j = 0; float

#include <stdio. h> main(void) { int i = 0; int j = 0; float num 1; /* multiply ½ with num 1*/ num 1 = 16. 0; while(i<2) { j = 0; while(j<2){ num 1 = 1/2*num 1; j = j + 1; } i = i + 1; } printf(“num 1 = %. 2 f”, num 1); } 1. num 1 = 0. 00 2. num 1 = 1. 000000 3. num 1 = 1. 00

#include <stdio. h> main(void) { int i = 0; int j = 0; float

#include <stdio. h> main(void) { int i = 0; int j = 0; float num 1; /* multiply ½ with num 1*/ num 1 = 16. 0; while(i<2) { j = 0; while(j<2){ num 1 = num 1*1/2; j = j + 1; } i = i + 1; } printf(“num 1 = %. 2 f”, num 1); } 1. num 1 = 0. 00 2. num 1 = 1. 000000 3. num 1 = 1. 00

#include <stdio. h> main(void) { int i = 0; int j = 0; float

#include <stdio. h> main(void) { int i = 0; int j = 0; float num 1; /* multiply ½ with num 1*/ num 1 = 16. 0; while(i<2) { j = 0; while(j<2){ num 1 = 1/2*num 1; j = j + 1; } i = i + 1; } printf(“num 1 = %d”, num 1); } 1. num 1 = 0. 00 2. num 1 = 1. 000000 3. num 1 = who knows?

Reminder on syntax/proper format: while statement: If/else if/else statements: If (conditions) { actions; }

Reminder on syntax/proper format: while statement: If/else if/else statements: If (conditions) { actions; } else if (different conditions) { actions; } else { actions; } while (conditions) { actions; } Nested while statements: while (conditions) { actions; } Various actions: printf(“This is an action”); scanf(“%d”, &variable); newvariable = algebraic statements;