|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 C语言鱼c 于 2014-1-17 14:42 编辑
- /***********************************************************/
- /* 设一个函数process,在调用它的时候,每次实现不同的功能。*/
- /* 输入a和b两个数,第一次调用process时找出a和b中大者,*/
- /* 第二次找出其中小者,第三次求a与b之和。 */
- /***********************************************************/
- #include <stdio.h>
- void main()
- {
-
- int max(int, int ); /* 函数声明 */
- int min(int, int ); /* 函数声明 */
- int add(int, int ); /* 函数声明 */
- void process(int, int, int(*fun)()); /* 函数声明 */
-
- int a, b;
- printf("Endter a and b:");
- scanf("%d %d", &a, &b);
- printf("max = ");
- process(a, b, max);
- printf("min = ");
- process(a, b, min);
- printf("sum = ");
- process(a, b, add);
- }
- ///////////////////////////////////////////////////////////
- int max(int x, int y) /* 函数定义 */
- {
- int z;
-
- if( x > y )
- {
- z = x;
- }
- else
- {
- z = y;
- }
- return z;
- }
- int min(int x, int y) /* 函数定义 */
- {
- int z;
- if( x < y )
- {
- z = x;
- }
- else
- {
- z = y;
- }
- return z;
- }
- int add(int x, int y) /* 函数定义 */
- {
- int z;
-
- z = x + y;
- return z;
- }
- void process( int x, int y, int(*fun)() ) /* 函数定义 */
- {
- int result;
- result = (*fun)(x, y);
- printf("%d\n", result);
- return(result);
- }
复制代码 process函数定义;
如果把printf("%d\n", result);去掉就不行了;
为什么?????
|
|