ENGR 3 rocks
Your friendly TA Damon
Good list of VI commands Good online free guide to Linux (time-sucker) Good online free guide to C commands
To search these websites use Google in the following way tcsh site: or printf site:
Homework 7 Let’s get ‘er done. A quick example: Ask user to enter an integer. Make C determine if the integer is even or odd. Tell the user if it is even or odd. If the user entered zero, warn them about it.
/*A prorgram that determines if an integer is even or odd.*/ #include int main() { int integer; printf( "\nEnter an integer: " ); scanf( "%d", &integer ); /*If the user entered 0 then give error*/ if ( integer == 0 ) { printf(“Warning: Evenness of zero is disputed.\n"); return 1; }
/*use mod to determine if the integer is even*/ /*if the integer is divisible by 2 then it is even*/ if ( integer % 2 == 0 ) { printf( "It is an even integer.\n"); }/*if integer is not divisible by 2 then it must be odd*/ else { printf( "It is an odd integer.\n"); } return 0; }
% gcc evenodd.c -o evenodd.out % evenodd.out Enter an integer: 34.4 It is an even integer. % evenodd.out Enter an integer: 0 Warning: Evenness of zero is disputed.
Time to work on Homework 7.