|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- //process by myself
- #include <stdio.h>
- void main(int argc, char *argv[])
- {
- int fmax(int ,int );
- int fmin(int ,int );
- int fadd(int ,int );
- int a,b;
-
- void process(int a,int b ,int (*fun)());
-
- printf("please input a&b:");
- scanf("%d %d",&a,&b);
-
-
- printf("max=");
- process(a,b,fmax);
- printf("\nmin=\n");
- process(a,b,fmin);
-
- printf("add=");
- process(a,b,fadd);
-
-
-
- return 0;
- }
-
- int fmax(int a,int b)
- {
- int z;
- if(a>b)
- z=a;
- else z=b;
- return(z);
- }
-
- int fmin(int a,int b)
- {
- int z;
- if(a<b)
- z=a;
- else
- z=b;
- return (z);
-
- }
- int fadd(int a,int b)
- {
- int z;
- z=a+b;
- return (z);
- }
-
-
- void process(int a,int b,int(*fun)())
- {
- int result;
- result = (*fun)(a, b);
- printf("%d\n", result);
- }
复制代码 //wrong wrong wrong- /***********************************************************/
- /* 设一个函数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);
- }
复制代码 // 运行完全流畅,ok |
|