Chapter16ex2.c 736 B

1234567891011121314151617181920212223242526
  1. // Example program #2 from Chapter 16 of Absolute Beginner's Guide
  2. // to C, 3rd Edition
  3. // File Chapter16ex2.c
  4. /* This program loops through 10 numbers and prints a message that
  5. varies whether the program is odd or even. It tests for odd and
  6. if the number is odd, it prints the odd message and then starts
  7. the next iteration of the loop using continue. Otherwise, it
  8. prints the even message. */
  9. #include <stdio.h>
  10. main()
  11. {
  12. int i;
  13. // Loops through the numbers 1 through 10
  14. for (i = 1; i <= 10; i++)
  15. {
  16. if ((i%2) == 1) // Odd numbers have a remainder of 1
  17. {
  18. printf("I'm rather odd...\n");
  19. // Will jump to the next iteration of the loop
  20. continue;
  21. }
  22. printf("Even up!\n");
  23. }
  24. return 0;
  25. }