|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/h4/oddEven.c
/*
oddEven.c
You will be taking your oddEven program in h3 and modify it so that the code
that calculates whether a number is odd or even is in a seperate function.
main has already been finished for you, you do not need to change anything in
main. the function isEven has been started, but it needs the code in order to
perform correctly.
*/
#include <stdio.h>
int isEven(int); //function prototype
int main(){
int num, rt; //variable declaration
printf("Please enter a number> "); //ask the user for a number
scanf("%d", &num);//use scanf to get that number
rt = isEven(num); //calling the function "isEven" with value "num" and
//putting the return value in rt.
//isEven returns 1 if the number is even, 0 if the number is odd
if(rt == 1) //isEven returned 1
printf("%d is even\n", num);
else //isEven returned 0
printf("%d is odd\n", num);
return 0;
}
//function definition
int isEven(int x){
/*
Here, you will put the code that calculates whether or not a number is
even. Have the function return a 1 if the number is even, or a 0 if the
number is odd. Do NOT put any printf statements inside the function.
*/
}
|