C Programming (Hemopurification a) after-school answer to the first chapter title

5. Title: Output the following pattern (see operation results)
Code:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf("******************************\n\n");
    printf("V e r y   g o o d !\n\n");
    printf("******************************");
    return 0;
 }

operation result:

******************************
V e r y   g o o d !
******************************

6. Title: writing a C program, inputs a, b, c, and outputs the maximum value.
Code 1:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    float max(float x,float y,float z);
    float a,b,c;
    printf("输入三个数字求最大值:");
    scanf("%f%f%f",&a,&b,&c);
    printf("最大值为:%f",max(a,b,c));
    return 0;
}
float max(float x,float y,float z)
{
    float t;
    if(x>y)
        t=x;
    else
        t=y;
    if(t>z)
        return t;
    else
        return z;
}

Code 2 (Advanced Edition):

#include <stdio.h>
#include <stdlib.h>
int main()
{
    float max(float x,float y);
    float a,b,c;
    printf("输入三个数字求最大值:");
    scanf("%f%f%f",&a,&b,&c);
    printf("最大值为:%f",max(max(a,b),c));
    return 0;
}
float max(float x,float y)
{
    return x>y?x:y;
}

operation result:

输入三个数字求最大值:4.4 5.5 6.6
最大值为:6.600000
Published an original article · won praise 1 · views 59

Guess you like

Origin blog.csdn.net/hahaxiaojiejie/article/details/104258510