How would I write this function in C (pointers)?

Hey guys, I am encountering pointers with C presently, could an individual please demonstrate me how you can write this kind of function

emptiness int_divide(int numerator, int denominator, int *quotient, int * remainder)

I would like it to go back the quotient and the remainder, I just simply don’t discover how to go to sort it out.
Thanks for ones help!!

If you’re struggling with pointers, I’m sorry to say that the prior answer is going to do nothing to solve your bafflement.In the actual divide job the int* arguments have to be dereferenced as a way to store the outcome in the particular caller’s rules.See underneath for how I did it.Likewise, it’s a good suggestion to ensure you don’t break down by actually zero.Note that we used this library function div, and you could just about as very easily do the actual / in addition to % yourself to calculate the quotient and also remainder.

#include
#include

emptiness divide(int, int, int*, int*);

int main(int argc, char *argv)
int your, b, q, r;

divide(a = 42, b = YOUR FIVE, &q, &r);
printf(“%d / %d = %d rest %d\n”, your, b, q, r);
divide(a = TWO, b = 0, &q, &r);
printf(“%d / %d = %d rest %d\n”, your, b, q, r);

give back 0;

emptiness divide(int by, int ful, int *quot, int *rem )
div_t z;

*quot = *rem = 0;
in the event that (y! = 0)
z = div(x, y);
*quot = z.quot;
*rem = z.rem;

#if 0

Application output:

42 / FIVE = 8-10 remainder 2
TWO / 0 = 0 rest 0

#endif

int main()

int q, r;
int_divide(3, 5, &q, &r);
pritnf(“%d%d”, q, r);

emptiness int_divide(int n1, int n2, int *qo, int *rem)

qo = n1/n2;
rem = n1%n2;

void int_divide(int numerator, int denominator, int *quotient, int * remainder)

*quotient = numerator/denominator;
*remainder = numerator%denominator;

Leave a Reply