C++求最小值

来源:百度知道 编辑:UC知道 时间:2024/05/20 16:45:12
输入三个整数,求出其中最小(要求使用条件表达式)(在线等)

#include<iostream.h>
void main()
{
int a,b,c,min;
cout<<"input a,b,c:"<<endl;
cin>>a>>b>>c;
min=(a<b?a:b)<c?(a<b?a:b) :c ;
cout<<"min="<<min<<endl;
}

int min(int a,int b,int c)
{
int ret=0;
ret = a>b?b:a ;
ret = ret>c?c:ret;
retturn ret;
}

int min3(int v1, int v2, int v3)
{
return (v1 > v2) ? ((v2 > v3) ? v3 : v2) : ((v1 > v3) ? v3 : v1);
}