www.rtmj.net > C++编程题 编写一个函数mAx,用于比较三个整数大小...

C++编程题 编写一个函数mAx,用于比较三个整数大小...

#include using namespace std; int max(int a, int b, int c) { if(b>a) a=b; if(c>a) a=c; return a; } void main(void) { int a, b, c; cin>>a>>b>>c; cout}

#include <stdio.h> void pi (int a,int b,int c); void main (void) { int a,b,c; printf ("input: "); scanf ("%d%d%d",&a,&b,&c); pi (a,b,c); } void pi (int a,int b,int c) { int max,t; if (a<b) { t=a; a=b; b=t; } if (a<c) { t=a; a=c; c=t; } if (b<c) { t=b; b=c; c=t; } printf ("%d %d %d",a,b,c); }

double max(double a,double b,double c){ double m; if(a>b) m=a; else m=b; if(c>m) m=c; return m;}

int max(int a,int b,int c) { return (a>b?a:b)>c?(a>b?a:b):c; } int main() { int a=1,b=3,c=2; printf("最大值为:%d\n",max(a,b,c)); return 0; }

if(a<b) { if(b<c) {max=c;mid=b;min=a;} else if(a<c) {max=b;mid=c;min=a;} else {max=b;mid=a;min=c;}} else if(c<b) {max=a;mid=b;min=c;} else if(a<c) {max=c;mid=a;min=b;} else {max=a;mid=c;min=b;} 应该是这样,因为我是学的c语言,所有没法

#include <stdio.h> int Max1(int a,int b){ return a>b?a:b; } double Max1(double a,double b){ return a>b?a:b; } int Max1(int a,int b,int c){ return Max1(a,Max1(b,c)); } double Max1(double a,double b,double c){ return Max1(a,Max1(b,c)); } int main(){ int

修改后的代码:#includeint max(int a,int b,int c){ int d; d=a; if(b>d) d=b; if(c>d) d=c; return d;}void main(){ int a[5],i,m; printf("请输入数组的5个元素"); for(i=0;i 评论0 0 0

#include void compare(int &a,int &b,int &c){ int large,mid,small,t; if(a 评论0 0 0

int max(int a,int b){if(a>b)return a;elsereturn b;};int max(int a,int b,int c){int max;if(a>b)max=a;elsemax=b;if(max>c)return max;elsereturn c;};int max(int A[,int n)//A是存放多个元素的数组,n是元素个数{max=A[0];for(int i=1;i<n;i++)if(A[i]>max)max=A[i];return max;};

public class compareA{ public void compareA();//构造函数 public int whoisbigger(int i,int j,int k) { int []a=new int[3]{i,j,k}; int max=a[0]; for(int n=0;nmax) {max=a[n];} } return max; }}public class compareB{ compareA comA=new compareA(); int a=2,b=10,c=20,d; d=comA.whoisbigger(a,b,c); Console.Write(d);}

网站地图

All rights reserved Powered by www.rtmj.net

copyright ©right 2010-2021。
www.rtmj.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com