C/C++教程

c语言 8-2

本文主要是介绍c语言 8-2,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、

#include <stdio.h>

#define max(x, y) ((x > y) ? x : y) 

int main(void)
{
    int a, b, c, d;
    puts("please input four integers.");
    printf("a = "); scanf("%d", &a);
    printf("b = "); scanf("%d", &b);
    printf("c = "); scanf("%d", &c);
    printf("d = "); scanf("%d", &d);
    printf("method1 int max = %d\n", max(max(a,b), max(c,d)));
    printf("method2 int max = %d\n\n", max(max(max(a,b),c),d));
    
    double m, n, i, j;
    puts("please input four doubles.");
    printf("m = "); scanf("%lf", &m);
    printf("n = "); scanf("%lf", &n);
    printf("i = "); scanf("%lf", &i);
    printf("j = "); scanf("%lf", &j);
    printf("method1 double max = %f\n", max(max(m,n),max(i,j)));
    printf("method2 double max = %f\n", max(max(max(m,n),i),j));
    
    return 0;
}

 

这篇关于c语言 8-2的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!