When I ran this code and provided 28000/3
as input, it showed:
28000/32766 = 0
.
Why on earth would this happen? I'm new to c and this is really confusing.
#include <stdio.h>
int main(void) {
int divide(int a, int b, int *result);
int a, b;
scanf("%d %d", &a, &b);
int c;
if (divide(a, b, &c)) {
printf("%d/%d=%d\n", a, b, c);
}
return 0;
}
int divide(int a, int b, int *result) {
int ret = 1;
if (b == 0)
ret = 0;
else {
*result = a / b;
}
return ret;
}