1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <stdio.h>
#include <stdlib.h>
int mult(int x, int y, int *err)
{
int res=x*y;
if (err)
{
if (x) (*err)=(res / x) == y ?0 :1;
else {
if (y) (*err)=(res / y) == x ?0 :1;
else (*err)=0;
}
}
return res;
}
int main(int argc, char *argv[])
{
int x, y, res;
int err;
x=10;
y=20;
res=mult(x, y, NULL);
printf("%d * %d=%d\n", x, y, res);
x=10;
y=20;
res=mult(x, y, &err);
printf("%d * %d=%d (err=%d)\n", x, y, res, err);
x=9000000;
y=900000;
res=mult(x, y, &err);
printf("%d * %d=%d (err=%d)\n", x, y, res, err);
} |
Partager