當前位置:首頁 » 編程語言 » 三個數排序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;
}

熱點內容
php辦公系統 發布:2025-07-19 03:06:35 瀏覽:895
奧德賽買什麼配置出去改裝 發布:2025-07-19 02:53:18 瀏覽:37
請與網路管理員聯系請求訪問許可權 發布:2025-07-19 02:37:34 瀏覽:185
ipad上b站緩存視頻怎麼下載 發布:2025-07-19 02:32:17 瀏覽:839
phpcgi與phpfpm 發布:2025-07-19 02:05:19 瀏覽:523
捷達方向機安全登錄密碼是多少 發布:2025-07-19 00:57:37 瀏覽:689
夜魔迅雷下載ftp 發布:2025-07-19 00:39:29 瀏覽:97
增值稅票安全接入伺服器地址 發布:2025-07-19 00:20:45 瀏覽:484
solidworkspcb伺服器地址 發布:2025-07-18 22:50:35 瀏覽:820
怎麼在堆疊交換機里配置vlan 發布:2025-07-18 22:42:35 瀏覽:628