1.编写程序求俩个数的最大值,使用函数完成。

#include<stdio.h>
int main(){
    int max(int a,int b);
    int a=19,b=34;
    int m=max(a,b);
    printf("m=%d",m);
    return 0; 
} 
int max(int a,int b){
    int c;
    if(a>b)c=a;
    else c=b;
    return c;
}

2.已知一个函数

编写函数Fum1实现上式,并返回函数值。在main函数调用Fum1函数,接受输入的x值,并输出函数值,例如:输入3.5,输出6.

#include<stdio.h>
int main(){
    int Fun1(double);
    double x;
    scanf("%lf",&x);
    double y;
    y=Fun1(x);;
    printf("%lf",y);
    return 0;
}
int Fun1(double x){
    double c;
    if(x>=10)c=2*x;
    else
    if(x<1)c=x;
    else c=2*x-1;
    return c;
}
End
最后修改:2021 年 03 月 30 日
如果觉得我的文章不错,请随手点赞~