57 lines
1.1 KiB
C
57 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include "gm.h"
|
||
|
void printres(char *,DEC *);
|
||
|
void main(void);
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
DECP x, y, z;
|
||
|
DEC *p;
|
||
|
char s[40];
|
||
|
|
||
|
do {
|
||
|
printf(" First number (x) : ");
|
||
|
scanf("%s", s);
|
||
|
p = ConvAsciiToDecimal(x, s);
|
||
|
} while (!p);
|
||
|
do {
|
||
|
printf("Second number (y) : ");
|
||
|
scanf("%s", s);
|
||
|
p = ConvAsciiToDecimal(y, s);
|
||
|
} while (!p);
|
||
|
|
||
|
printres("x = ", x);
|
||
|
printres("y = ", y);
|
||
|
p = AddDecimal(z, x, y);
|
||
|
printres("x + y = ", p);
|
||
|
p = SubtractDecimal(z, x, y);
|
||
|
printres("x - y = ", p);
|
||
|
p = MultiplyDecimal(z, x, y);
|
||
|
printres("x * y = ", p);
|
||
|
p = DivideDecimal(z, x, y);
|
||
|
printres("x / y = ", p);
|
||
|
p = MultiplyDecimalAndRound(z, x, y, 2);
|
||
|
printres("x * y (rounded) = ", p);
|
||
|
p = MultiplyDecimalAndTruncate(z, x, y, 2);
|
||
|
printres("x * y (truncated) = ", p);
|
||
|
p = DivideDecimalAndRound(z, x, y, 2);
|
||
|
printres("x / y (rounded) = ", p);
|
||
|
p = DivideDecimalAndTruncate(z, x, y, 2);
|
||
|
printres("x / y (truncated) = ", p);
|
||
|
}
|
||
|
|
||
|
void printres(str, pd)
|
||
|
char *str;
|
||
|
DEC *pd;
|
||
|
{
|
||
|
char sd[22];
|
||
|
|
||
|
printf("%20s", str);
|
||
|
if (pd) {
|
||
|
ConvDecimalToAscii(sd, pd);
|
||
|
printf("%s\n", sd);
|
||
|
}
|
||
|
else
|
||
|
printf("undefined\n");
|
||
|
}
|