73.5k views
0 votes
Write a C function check(x, y, n) that returns 1 if both x and y fall between 0 and n-1 inclusive. The function should return 0 otherwise. Assume that x, y and n are all of type int.

1 Answer

7 votes

Answer:

See comments for line by line explanation (Lines that begins with // are comments)

The function written in C, is as follows:

//The function starts here

int check(x,y,n)

{

//This if condition checks if x and y are within range of 0 to n - 1

if((x>=0 && x<=n-1) && (y>=0 && y<=n-1))

{

//If the if conditional statement is true, the function returns 1

return 1;

}

else

{

//If the if conditional statement is false, the function returns 0

return 0;

}

//The if condition ends here

}

//The function ends here

Step-by-step explanation:

User Akhalsa
by
6.0k points