Friday 26 September 2014

Function to return the quotient

Write a function called divide that takes two non-negative integers : a and b and returns the quotient of a divided by b, if b is a factor of a, else it returns -1.

Note: In this assignment the main() function is given to you. The given code for main() cannot be changed by you and divide() is being called from inside that. You only need to write the divide function.

Also note that the #include line is also provided so you do not need to add it while writing the divide() function.



/* 
   The code given in the black background _above_ this editor 
   box will be automatically added _before_ your code. 
   So assume this code is present when you write your code.
   For coding on your local compiler, copy paste the code 
   into your editor.
*/


// Insert your code for divide() below this line

int divide(int a,int b)
{int d;if(a%b==0)
{d=a/b;

return d;


}
else
return -1;


}

/* 
   The code given in the black background _below_ this editor 
   box will be automatically added _after_ your code. 
   So assume this code is present when you write your code.
   For coding on your local compiler, copy paste the code 
   into your editor.
*/

No comments:

Post a Comment