Can someone please explaine to me how to write a function program. Using prototypes just throws me.
Here is my prompt:
write a function called is _is even that has one input parameter and int called number which is a number the user wants to determine is even or not. The Function returns an integer which has a value of 1 if the number passed is even and has a value of 0 if the number passed is not even.
I'll paste the mess I came up with below.... Ugh
btw, i know it says to only write the function, but i'm going for the full program in hopes of better understanding it. My program compiles, but doesn't return anything.
#include <stdio.h>
int is_even(int number);
int main(void)
{
int number;
int answer;
printf("Enter a number: ");
scanf("%d", &number);
answer=is_even( number);
return;
}
int is_even(int number)
{
int answer=number%2 ;
if(answer==0)
return(1);
else
return(0);
}
Here is my prompt:
write a function called is _is even that has one input parameter and int called number which is a number the user wants to determine is even or not. The Function returns an integer which has a value of 1 if the number passed is even and has a value of 0 if the number passed is not even.
I'll paste the mess I came up with below.... Ugh
btw, i know it says to only write the function, but i'm going for the full program in hopes of better understanding it. My program compiles, but doesn't return anything.
#include <stdio.h>
int is_even(int number);
int main(void)
{
int number;
int answer;
printf("Enter a number: ");
scanf("%d", &number);
answer=is_even( number);
return;
}
int is_even(int number)
{
int answer=number%2 ;
if(answer==0)
return(1);
else
return(0);
}
Comment