Given the following C function prototype that accepts two integer arguments.
Complete the function and return 1 if a > b , return -1 if a < b and return 0 if a is equal to b.
C function to complete int compare(int a, int b)
Write a full c program that has the header required and will accept the user entry.
Solution:
Function prototype:
A function prototype is simply the declaration of a function that specifies the function's name, parameters, and return type. It doesn't contain a function body.
Code Screenshot:

Output Screenshot:
If a > b:

if a < b:

if a = b:

Code in Text Format:
#include<stdio.h> // header file
int compare(int a, int b); // function prototype
int main(){
int a, b, result;
// Asking inputs from user
printf("Enter a value: ");
scanf("%d",&a);
printf("Enter b value: ");
scanf("%d",&b);
result = compare(a,b); // function call
printf("%d",result);
return 0;
}
int compare(int a, int b){ // function definition
if(a > b){
return 1; // return statement
}
else if(a < b){
return -1; // return
statement
}
else if(a == b){ // you can use else or else if
return 0; // return statement
}
}
Outputs in Text Format:
if a > b:
Enter a value: 5
Enter b value: 4
1
if a < b:
Enter a value: 2
Enter b value: 3
-1
if a= b:
Enter a value: 4
Enter b value: 4
0
Given the following C function prototype that accepts two integer arguments. Complete the function and return...
Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...
Write a function prototype for a function that will accept a single integer. Create a function that accepts an integer and determines if the integer is odd or even. create a smsll program that asks a user for an integer and calls a function that determines if the integer is even or odd. This is a C language program.
design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. for example if 7 and 12 are passed as arguments to the function the function should return 12. use the function in a program that prompts the user to enter two integer values. the program should display the value that is the greater of the two.
1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...
Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example: multiply([ 1, 2, 3], 3) → 6 multiply([1, 1, 4 ,2], 4) → 8 multiply([7, 0, 0, 7, 0, 7],...
Write a statement that declares a prototype for a function divide that takes four arguments and returns no value. The first two arguments are of type int. The last two arguments arguments are pointers to int that are set by the function to the quotient and remainder of dividing the first argument by the second argument. The function does not return a value. (C Program)
(C programming) (Function arguments) Design a function prototype that can accept any type of argument and return an integer.
I am supposed to a pseudocode function named max that accepts two integer values as arguments and returns the value that is greater of the two. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is greater of the two. Is everything correct and complete? //Pseudocode //This function takes two integers as parameters: x and y Begin : Max(x,y) If(x>y) then MAX=x Else MAX=y End if Return...
(C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...
C++ //Write prototype for function factorial that accepts an int num and returns an int /* WITH LOOP OF YOUR CHOICE: Write code for function factorial that accepts an int num and returns the num's factorial factorial(5); 1*2*3*4*5 returns 120 DON'T FORGET TO WRITE TEST CASE. */ //write includes statements //write using statements for cin and cout /* Use a do while loop to prompt the user for a number, call the factorial function, and display the number's factorial. Also,...