The question is this:
Construct a function that takes two integer values a
and b
, return (passing by reference) the quotient, div, and the remainder division, mod, from a
to b
. The function should return -1
if it is not possible to perform operations and 0
if it is possible. An algorithm to use such a function should be created by treating the function return.
I made the code like this, but I have no idea what I'm doing:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int div (int *a, int *b)
{
int resultado, resto, aux;
if (*b==0)
{
return -1;
}
else
{
resultado = (*a / *b);
resto = (*a % *b);
return 0;
}
}
int main (void)
}
int a, b, *resto, *resultado, *aux;
printf ("Digite o valor do dividendo: ");
scanf ("%i", &a);
printf ("Digite o valor do divisor: ");
scanf("%i", &b);
div (&a, &b);
if (div == 0)
{
printf ("O resultado da divisao eh: %i ", resultado);
printf ("O resto da divisao eh: %i", resto);
}
else
{
printf ("Nao eh possivel realizar uma divisao por 0");
}
return 0;
}