當前位置:首頁 » 編程語言 » 三個數排序c語言

三個數排序c語言

發布時間: 2025-02-28 03:36:50

1. 用C語言對三個數從大到小排序

最小用min 不要用main. 這個是主函數名 不能和變數重復的.

#include<stdio.h>
intmain(void)
{
inta,b,c,max,min;
scanf("%d%d%d",&a,&b,&c);
max=a>b?a:b;
min=a<b?a:b;
if(c>max)max=c;
if(c<min)min=c;//這里用<
printf("從大到小排序:%d%d%d ",max,a+b+c-max-min,min);
return0;
}

2. 如何用函數實現三個數的排序(用的是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返回this 發布:2025-10-20 08:28:16 瀏覽:645
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:936
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:632
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:821
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:731
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1066
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:299
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:160
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:852
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:763