只有3個(gè)數(shù),窮舉比較實(shí)現(xiàn)很方便,所以在輸入3個(gè)數(shù)后直接利用if...else if結(jié)構(gòu)比較大小取中值輸出即可。代碼如下:
創(chuàng)新互聯(lián)公司主要從事網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)巴州,十載網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):18980820575
#include?"stdio.h"
int?main(int?argc,char?*argv[]){
int?a,b,c;
printf("Input?3?integers...\n");
scanf("%d%d%d",a,b,c);
printf("In?the?middle?of?the?number?is?");
if(a=b??b=c?||?c=b??b=a)
printf("%d\n",b);
else?if(b=a??a=c?||?c=a??a=b)
printf("%d\n",a);
else
printf("%d\n",c);
return?0;
}
運(yùn)行樣例如下:
沒(méi)有包含頭文件conio.h,
還有倒數(shù)第三行改為printf("%d\n",zws(a,b,c));
#includeconio.h
#includestdio.h
int zws(int a, int b, int c){
int ans;
if (a = b a = c) ans = a;
if (a = b a = c) ans = a;
if (b = a b = c) ans = b;
if (b = a b = c) ans = b;
if (c = a c = b) ans = c;
if (c = a c = b) ans = c;
return ans;
}
int main()
{
int a, b, c;
printf("please input 3 integar:");
scanf("%d %d %d", a, b, c);
printf("%d\n",zws(a, b, c));
getch();
}
#includestdio.h
#define?N?1001
void?bubblesort(int?*list,int?len)?//冒泡排序
{
int?i,j;
int?temp;
for(i=0;ilen?-?1;i++)
for(j=0;jlen-i?-?1;j++)?
{
if(list[j+1]list[j])
{
temp=list[j+1];
list[j+1]=list[j];
list[j]=temp;
}
}
}
int?main(){
int?num;
int?tar[N];
scanf("%d",?num);
while(num?!=?0){
for(int?i?=?0;?i?num;?i++){
scanf("%d",?tar[i]);
}
bubblesort(tar,?num);
if(num?%?2?==?0){
printf("%lg\n",(tar[num/2]?+?tar[num/2?-?1])?/?2.0);?
}else{
printf("%lg\n",?tar[num/2]*1.0);
}
scanf("%d",num);
}
return?0;
}