Discussion Notes 3

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

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

View Full Document Right Arrow Icon
EME 5 Discussion 3 Even and Odd Integers while Loop for Loop Flowchart switch Statement break and continue Statements Function
Background image of page 1

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

View Full DocumentRight Arrow Icon
Even and Odd Integers Write a program that reads an integer and prints it out when it is an even integer.
Background image of page 2
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; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
while Loop Write a program that prints out 1, 2, 3, 4, 5 using a while loop.
Background image of page 4
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; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
for Loop Write a program that prints out 1, 2, 3, 4, 5 using a for loop.
Background image of page 6
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; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online