1
That’s the thing about:
Build a function that takes two integer values a
and b
, returns (passing by reference) the quotient, div, and the rest division, mod, of a
for b
. The function must return -1
where operations cannot be carried out, and 0
if possible. An algorithm to use such a function must be created, treating the return of the function.
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;
}
Your code is a bit messy. Perhaps the IDE was putting up either tab or spacing. If you can fix the code it would be much easier to read
– Jefferson Quesado
was bad, first time using this, I don’t even know how to edit the post, I’ll look here...
– Jansen Costa
Do the [tour], there much of how you should use the site is explained
– Jefferson Quesado