/* * evenorodd.c * Selftest Problem5 * Chapter 6 * John Stile * Purpose: Write a program named evenorodd.c that reads an integer * and determines and prints if the number is even or odd. * Display an error message when a float is entered instead of an integer. */ #include int main(void) { float read; // declare float variable read printf(" Enter an integer: "); scanf("%f", &read); // read from stdin, // interpret as a float // store at address location of var read getchar(); // clear stdin if ( (int)read != read ) // cast read to an int // compare the result with the original { printf("That is not an integer: %f\n", read ); } else if( read == 0 ) { printf("Zero is not even or odd. it's zero\n"); } else { if ( read == ( 2* ( (int)read/2) ) ) // cast read to int // divide int read by 2 // multiply result by 2 // does result equal origninal { printf("The number %d is even\n", read); } else { printf("The nubmer %d is odd\n", read); } } return 0; }