① 急求谢啦C语言编程 按从大到小排序三个数
#include <stdio.h>
void main()
{
int a,b,c,t;
printf("输入三个数:空格隔开"); /*提示输入3数*/
scanf("%d %d %d",&a, &b, &c);/*由键盘输入*/
printf("排列后:%d %d %d\n",a,b,c);
if(a<b)
{
t=b;
b=a;
a=t;
} /*实现ab互换*/
if(a<c)
{
t=c;
c=a;
a=t;
} /*实现ac互换*/
if(b<c)
{
t=c;
c=b;
b=t;
} /*实现bc互换*/
printf("排列后:%d %d %d \n",a,b,c);
}
② java 编程题 对给定的3个数进行排序按从大到小的顺序排列输出
//第一种简单方法:
public class C123{
public static void main(String args[]){
int a=34,b=62,c=5;,smallest;
sort3(a,b,c);}
static void sort3(){
int temple;
if(x>y){temple=x;x=y;y=temple;}
if(x>z){temple=x;x=z;z=temple;}
if(y>z){temple=y;y=z;z=temple;}
System.out.println("Sorted:"+x+","+y+","+z);
return;
}
}
//第二种简单方法:
import java.util.*;
class ArraySort{
public static void main(String args[]){
int a[]={,23,64,25};
Arrays.sort(a);
for(i=0;i<a.lengh;i++)
System.out.println(a[i]+" ");
}
}
如果调用方法的话就更好了,你自己琢磨.
③ 如何用函数实现三个数的排序(用的是C语言)
一:全局变量
#include<stdio.h>
inta,b,c;//定义三个全局变量
voidsort()//不需要参数
{
intt;
if(a>b)
{
t=a;a=b;b=t;
}
if(b>c)
{
t=b;b=c;c=t;
}
if(a>b)
{
t=a;a=b;b=t;
}
}
intmain()
{
printf("输入:");
scanf("%d%d%d",&a,&b,&c);
sort();
printf("排序:%d<%d<%d ",a,b,c);
return0;
}
④ 用java编写程序对三个整数排序
简单的整数排序,可以用选择排序、冒泡排序、插入排序。
code demo:
publicclassSortDemo{
publicstaticvoidmain(String[]args){
int[]ary={3,1,5,6,2,6,8,3};
//ary=selectionSort(ary);
ary=insertSort(ary);
//将数组ary连接为一个字符串:Arrays.toString(ary);
//如:{1,2,3}->"[1,2,3]"
Strings=Arrays.toString(ary);
System.out.println(s);
}
/**选择排序*/
publicstaticint[]selectionSort(int[]ary){
for(inti=0;i<ary.length-1;i++){
for(intj=i+1;j<ary.length;j++){
if(ary[i]>ary[j]){
inttemp=ary[i];
ary[i]=ary[j];
ary[j]=temp;
}
}
}
returnary;
}
/**冒泡排序*/
publicstaticint[]bubleSort(int[]ary){
for(inti=0;i<ary.length-1;i++){
for(intj=0;j<ary.length-(1+i);j++){
if(ary[j]>ary[j+1]){
inttemp=ary[j];
ary[j]=ary[j+1];
ary[j+1]=temp;
}
}
}
returnary;
}
//插入排序
publicstaticint[]insertSort(int[]ary){
//int[]ary={3,1,5,6,2,6,8,3};
for(inti=1;i<ary.length;i++){
inttemp=ary[i];
intj;
for(j=i-1;j>=0&&temp<ary[j];j--){
//if(temp<ary[j]){
ary[j+1]=ary[j];
//}else{
//break;//找到插入位置
//}
}
ary[j+1]=temp;//插入操作
}
returnary;
}
}