@[TOC]第七章(用函数实现模块化程序设计)
例7.1
# include<stdio.h>
int main()
{
void print_star();
void print_message();
print_star();
print_message();
print_star();
return 0;
}
void print_star()
{
printf("******************\n");
}
void print_message()
{ printf("How do you do!\n");
}
运行结果如下:
例7.2
# include<stdio.h>
int main()
{int max(int x,int y);
int a,b,c;
printf("please enter two integer numbers:");
scanf("%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);
}
运行结果如下:
例7.3
# include<stdio.h>
int main()
{int max(float x,float y);
float a,b;
int c;
scanf("%f,%f,",&a,&b);
c=max(a,b);
printf("max is %d\n",c);
return 0;
}
int max(float x,float y)
{
float z;
z=x>y?x:y;
return(z);
}
运行结果如下:
例7.4
# include<stdio.h>
int main()
{ float add(float x,float y);
float a,b,c;
printf("Please enter a and b:");
scanf("%f,%f",&a,&b);
c=add(a,b);
printf("sum is %f\n",c);
return 0;
}
float add(float x,float y)
{
float z;
z=x+y;
return (z);
}
运行结果如下: