1.输入两个整数,输出其中值较大者。要求用函数来找到大数
#include<stdio.h>
int main()
{
int max(int x, int y);
int a, b, c;
printf("please enter two integer numbers:");
scanf_s("%d,%d", &a, &b);
c = max(a, b);
printf("max is %d\n", c);
return 0;
}
int max(int x, int y)
{
int z;
z = x > y ? x : y;
return (z);
}
运行结果:
2.输入两个实数,用一个函数求出它们之和
#include<stdio.h>
int main()
{
float add(float x, float y);
float a, b, c;
printf("please enter a and b:");
scanf_s("%f,%f", &a, &b);
c = add(a, b);
printf("sum is %f\n", c);