______________________________________________________________________________________________________________
#include <stdio.h>
float max(float x,float y);
void main()
{ float a,b,m;
scanf("%f,%f",&a,&b);
m=max(a,b);
printf("Max is %f\n",m);
}
float max(float x,float y)
{
float temp;
if (x<y)
{temp=x;
x=y;
y=temp;
}
return(x);
}
7、从键盘输入你和你朋友的年龄,编成判断谁的年龄最大,并打印最大者的年龄。
#include <stdio.h>
void main()
{ int yourAge, hisAge;
printf("Please enter your age:");
scanf("%d", &yourAge); /*输入你的年龄 yourAge*/
printf("Please enter your friend's age:");
scanf("%d", &hisAge); /*输入你朋友的年龄 hisAge*/
if (yourAge >= hisAge)
{
printf("You are older! Your age is = %d\n", yourAge);
}
if (hisAge > yourAge)
{
printf("Your friend is older! HisAge age is = %d\n",
hisAge);
}}
8、键盘输入 2 个加数,再输入答案,如果正确,显示“right”,否则显示
“error”
评论0
最新资源