Discussion Notes 3

# Discussion Notes 3 - EME 5 Discussion 3 Even and Odd...

This preview shows pages 1–8. Sign up to view the full content.

EME 5 Discussion 3 Even and Odd Integers while Loop for Loop Flowchart switch Statement break and continue Statements Function

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Even and Odd Integers Write a program that reads an integer and prints it out when it is an even integer.
Even and Odd Integers (contd.) #include<stdio.h> int main() { int x; printf(“Please enter an integer: ”); scanf(“%d”, &x); if((x%2) == 0) { printf(“%d\n”, x); } return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
while Loop Write a program that prints out 1, 2, 3, 4, 5 using a while loop.
while Loop (contd.) #include <stdio.h> int main() { int x; x = 1; // Initialize x while(x <= 5) { // Test x if(x == 5) { printf("%d ", x); } else { printf("%d, ", x); } x = x+1; // Increment x } printf("\n"); return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
for Loop Write a program that prints out 1, 2, 3, 4, 5 using a for loop.
for Loop (contd.) #include<stdio.h> int main() { int x; for(x=1; x<=5; x=x+1) { if(x == 5) { printf("%d ", x); } else { printf("%d, ", x); } } printf("\n"); return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

Discussion Notes 3 - EME 5 Discussion 3 Even and Odd...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online