用C语言比较三个数的大小,并按照从大到小排序

拜托啦,时间紧啊

#include<stdio.h>

#include<math.h>

main()

{

 int a,b,c,i,j;

 printf("please input three side(数以空格分开):\n");

 int A[3];

 int t;

 scanf("%d %d %d",&a,&b,&c);

 A[0]=a;A[1]=b;A[2]=c;  

 for(j=0;j<2;j++)

  for(i=0;i<2-j;i++)  

      if(A[i]>A[i+1])

      {

      t=A[i];

      A[i]=A[i+1];

      A[i+1]=t;

      } 

  a=A[0];b=A[1];c=A[2]; 

  printf("%d > %d > %d",c,b,a);

  while(1);

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-02-05
#include <stdio.h>
#include <math.h>
int main(void)
{

int a,b,c;
printf("请输入任意三个整数a,b,c:");
scanf("%d%d%d",&a,&b,&c);
int s;
if(a>b)s=a,a=b,b=s;//比较a,b大小,通过赋值,使得a<b 。此语句目的:a<b
if(a>c)s=a,a=c,c=s;//进一步比较a,c大小,通过赋值得出最小值,并赋给a; 此语句目的:a<c
if(b>c)s=b,b=c,c=s;//最后比较出b,c中的较大值。
printf("从大到小的顺序依次是:%d%d%d",c,b,a);
return 0;
}
第2个回答  2012-03-21
#include <iostream>
#include<algorithm>
#define MaxSize 1001
using namespace std;

bool bCmp(int a,int b){
return a>b; //从大到小排序
}

void main(){
int a[MaxSize];
int n;//n是要排序数组的个数
int i;

while(1==scanf("%d",&n)){
for(i=1;i<=n;i++) //数组赋值
scanf("%d",&a[i]);

sort(&a[1],&a[n+1],bCmp); //用sort函数排序

for(i=1;i<=n;i++){ //输出排序后的数组
printf("%d ",a[i]);
if(i==n)
printf("\n");
}
}

}追问

这个...好多符号我不认识啊,超出我的学习范围了吧?能不能换个简单的?谢谢

追答

/*这个是循环的,还可以是if来判断的
#include
int main(){
return 0;
}你可以改成这样的
*/
#include
using namespace std;

void main(){
int i,j,k;
int a[3];
int max;

while(scanf("%d%d%d",&a[0],&a[1],&a[2])==3){
for(i=0;imax){
max=a[j];
k=j;
}
}
a[k]=a[i];
a[i]=max;
printf("%d ",a[i]);
if(i==2)
printf("\n");
max=0;
}
}
}
这个就是排序出来啊,3个数,我发的两个程序都可以排序啊,第一个是要输入排多少个数字,第二个程序是排序3个数字,你都不运行下吗

第3个回答  2012-03-21
#include <iostream>
using namespace std;
int main()
{ viod sort (int x,int y, int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x,int y,int z)
{
int temp;
if(x>y) {temp=x,x=y,y=temp;}
if(z<x) cout<<z<<','<<x<<','<<y<<endl;
else if(z<y) cout<<x<<','<<z<<','<<y<<endl;
else cout<<x<<','<<y<<','<<z<<endl;
}
前面是比较大小,后面是排序。这是课本上的例题。
程序很简单而且都是基本的格式追问

iostream using namespace std; viod sort cin......还有好几个不认识啊...

追答

这个是C++里面的。iostream这个就是 ,,using namespace std这句话是格式总要带上。cin就是输入。cout就是输出。坑爹呀。我忘记C语言的术语了。就是几个词不同,你用C语言替换下。自己能替换出来才算对这个基础程序看懂了。函数什么的都没变。

追问

\documents and settings\administrator\64龚俊xt3-1.cpp(4) : error C2065: 'viod' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'sort'
: error C2065: 'sort' : undeclared identifier
error C2144: syntax error : missing ')' before type 'int' error C2059: syntax error : ')'
: error C2373: 'sort' : rede

这个就是软件提示的错误...晕啊

追答

viod打错了。改成void这是个没有返回值的函数。if(x>y) {temp=x,x=y,y=temp;}
这个后面加分号; 尝试分析错误。

第4个回答  2021-11-04
#include <stdio.h>
int main(void)
{
int a,b,c;
printf("请输入任意三个整数a,b,c\n");
scanf("%d%d%d",&a,&b,&c);
int s;
if(a>b)s=a,a=b,b=s;
if(a>c)s=a,a=c,c=s;
if(b>c)s=b,b=c,c=s;
printf("结果为:\n%d>%d>%d",c,b,a);
return 0;
}