Write in C: 1.) Write the definition of a function isEven, which receives an int
ID: 3756378 • Letter: W
Question
Write in C:
1.) Write the definition of a function isEven, which receives an integer parameter and returns true if the parameter's value is even, and false otherwise.
So if the parameter's value is 7 or 93 or 11 the function returns false. But if the parameter's value is 44 or 126 or 7778 the function returns true.
2.) Given the integer variables x and y, write a fragment of code that assigns the larger of x and y to another integer variable max.
3.) Write the definition of a function max that has three int parameters and returns the largest.
Explanation / Answer
1).
Program:
#include<stdio.h>
char* isEven(int);
main()
{
int n;
printf("enter the number:");
scanf("%d",&n);
printf("%s",isEven(n));
}
char* isEven(int n)
{
if(n%2==0)
return "true";
else
return "false";
}
Sample Output:
enter the number: 11
false
2).
Program:
#include<stdio.h>
main()
{
int x,y,max;
printf("enter the values of x and y:");
scanf("%d%d",&x,&y);
if(x>y)
max=x;
else
max=y;
printf("The large value between %d and %d is: %d",x,y,max);
}
Sample Output:
enter the values of x and y: 2 3
The large value between 2 and 3 is: 3
3).
Program:
#include<stdio.h>
int max(int,int,int);
main()
{
int a,b,c;
printf("Enter the values of a,b and c:");
scanf("%d%d%d",&a,&b,&c);
printf("The largest value is:%d",max(a,b,c));
}
int max(int a,int b,int c)
{
if(a>b&&a>c)
return a;
else if(b>c)
return b;
else
return c;
}
Sample Output:
Enter the values of a,b and c: 1 2 3
The large value is: 3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.