用c++编写一个程序,用指向函数的指针实现求两个实数中的较大値和较小值
3个回答
展开全部
#include <iostream>
using namespace std;
int max(int num1, int num2)
{
return (num1>=num2 ? num1 : num2);
}
int min(int num1, int num2)
{
return (num1<=num2 ? num1 : num2);
}
main()
{
int *fun(int, int);
int a = 10, b = 20;
fun = max;
count<<"the larger integer is: "<<fun(a, b)<<endl;
fun = min;
count<<"the smaller integer is: "<<fun(a, b)<<endl;
}
using namespace std;
int max(int num1, int num2)
{
return (num1>=num2 ? num1 : num2);
}
int min(int num1, int num2)
{
return (num1<=num2 ? num1 : num2);
}
main()
{
int *fun(int, int);
int a = 10, b = 20;
fun = max;
count<<"the larger integer is: "<<fun(a, b)<<endl;
fun = min;
count<<"the smaller integer is: "<<fun(a, b)<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
float max(float x,float y)
{
return(x>y?x:y);
}
void main()
{
float (*ptr)(float, float);
float a,b,c;
ptr=max;
cin>>a>>b;
c=(*ptr)(a,b);
cout<<"a="<<a<<",b="<<b<<",max="<<c;
}
using namespace std;
float max(float x,float y)
{
return(x>y?x:y);
}
void main()
{
float (*ptr)(float, float);
float a,b,c;
ptr=max;
cin>>a>>b;
c=(*ptr)(a,b);
cout<<"a="<<a<<",b="<<b<<",max="<<c;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
float max(float a,float b)
{
return a>b?a:b;
}
float min(float a,float b)
{
return a<b?a:b;
}
void main()
{
float (*fun)(float,float);
float a = 1,b = 2;
fun = max;
printf("Max=%f\n",(*fun)(a,b));
fun = min;
printf("Min=%f\n",(*fun)(a,b));
}
float max(float a,float b)
{
return a>b?a:b;
}
float min(float a,float b)
{
return a<b?a:b;
}
void main()
{
float (*fun)(float,float);
float a = 1,b = 2;
fun = max;
printf("Max=%f\n",(*fun)(a,b));
fun = min;
printf("Min=%f\n",(*fun)(a,b));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询