c语言 8-1
1、
#include <stdio.h>
#define diff(x, y) ((x) - (y))
int main(void)
{
int a, b;
puts("please input two integers.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
printf("diff result: %d
", diff(a, b));
double m, n;
puts("please input two doubles.");
printf("m = "); scanf("%lf", &m);
printf("n = "); scanf("%lf", &n);
printf("diff result: %f
", diff(m, n));
return 0;
}
2、
#include <stdio.h> #define diff(x, y) ((x > y) ? (x - y) : (y - x)) int main(void) { int a, b; puts("please input two integers."); printf("a = "); scanf("%d", &a); printf("b = "); scanf("%d", &b); printf("result: %d ", diff(a, b)); double m, n; puts("please input two doubles."); printf("m = "); scanf("%lf", &m); printf("n = "); scanf("%lf", &n); printf("result: %f ", diff(m, n)); return 0; }