# int mainvoid int x2 xinitial2 int p5 int

• Slides: 7

int main(void) { int x=2, xinitial=2; int p=5; int i=1; for (i = 1; i<=p; i=i+1) { x = x*xinitial; } return 0; } 1. x = 32 2. x = 16 3. x = 4 4. x = 64

int main(void) { int x = 2, xinitial = 2; int p = 5; int i = 1; for (i = 1; i<=p; i=i*2) { x = x*xinitial; } return 0; } 1. x = 16 2. x = 8 3. x = 4 4. x = 32

int main(void) { int x = 2, xinitial = 2; int p = 6; int i = 1; for (i = 1; i<p; i=i+1) { x = x*xinitial; i = i + 1; } return 0; } 1. x = 16 2. x = 8 3. x = 4 4. x = 32

int main(void) { int x = 2, xinitial = 2; int p = 6; int i = 1; for (i = 1; i<p; i=i+1) { x = x*xinitial; i = i + 1; } while (i<p) { x = x*xinitial; i = i + 1; } return 0; } } Equivalent: YES OR NO

int main(void) { int x = 2, xinitial = 2; int p = 6; int i = 1; for (i = 1; i<p; i=i+1) { x = x*xinitial; i = i + 1; } while (i<p) { x = x*xinitial; i = i + 2; } return 0; } } Equivalent: YES OR NO

General flow loop Flowchart/Syntax counter initialized conditions True statements counter in(de)cremented False for (initialization; conditions; increment/decrement) { statements; }

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