加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

输入两个整数,然后让用户选择1或者2,选1是调用max函数,输出二

发布时间:2020-12-14 02:42:04 所属栏目:大数据 来源:网络整理
导读:#includestdio.hint main (){int max(int,int);int min(int x,int y);int (*p)(int,int);int a;int b;int c;int n;printf("enter a and b:");scanf("%d,%d",a,b);printf("choose 1 or 2:");scanf("%d",n);if(n == 1){p = max;}else if(n == 2){p = min;}c =
#include<stdio.h>

int main ()
{
	int max(int,int);
	int min(int x,int y);
	int (*p)(int,int);
	int a;
	int b;
	int c;
	int n;
	printf("enter a and b:");
	scanf("%d,%d",&a,&b);
	printf("choose 1 or 2:");
	scanf("%d",&n);
	if(n == 1)
	{
		p = max;
	}
	else if(n == 2)
	{
		p = min;
	}
	c = (*p)(a,b);
	printf("a = %d,b = %dn",a,b);
	if(n == 1)
	{
		printf("max = %dn",c);
	}
	else
	{
		printf("min = %dn",c);
	}
	return 0;
}

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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读