首页
/
每日頭條
/
圖文
/
c語言如何将數字從小到大排列
c語言如何将數字從小到大排列
更新时间:2026-07-20 21:52:09

題目要求:

輸入一個數字序列{a1,a2,…,an},将該序列進行排列,并輸出每一種排列方式。

#include "stdio.h" getStep(int m[]) /*顯示數陣中數字移動的步驟*/ { int i,j,tmp; for(i=0;i<7;i ) /*冒泡排序*/ for(j=0;j<7-i;j ) if(m[j]>=m[j 1]) { tmp = m[j]; m[j] = m[j 1]; m[j 1] = tmp; /*數據的交換*/ printf("(%d# --> 0#)\n",j 1); printf("(%d# --> %d#)\n",j 2,j 1); printf("(0# --> %d#)\n",j 2); /*輸出移動步驟*/ } printf("\n"); } Print(int m[]) /*打印出當前數陣的狀态*/ { printf(" [%d]--[%d]--[%d]\n",m[0],m[1],m[2]); printf(" | %c | %c | \n",92,47); printf(" [%d]--[ ]--[%d]\n",m[7],m[3]); printf(" | %c | %c | \n",47,92); printf(" [%d]--[%d]--[%d]\n",m[6],m[5],m[4]); } main() { int i , m[8]; printf("Please input 8 integer (1~8) to arrange this matrix\n"); for(i=0;i<8;i ) scanf("%d",&m[i]); printf("The initial data matrix is like\n"); Print(m); printf("\nMove Step:\n"); getStep(m); printf("The result of moving is\n"); Print(m); getche(); }

運行結果:

c語言如何将數字從小到大排列(c語言計算數字的排列)1

運行結果

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
怎樣選擇鏡片不被坑
怎樣選擇鏡片不被坑
你知道通用鏡片是以25度為間隔嗎?戴上新配的眼鏡,你會感覺不适嗎?你知道自己近視的真實度數嗎?01:你的鏡片度數可能在驗光時就出現了偏差!【什麼是屈光不正?】屈光不正是指眼在不使用調節時平行光線通過眼的屈光作用後不能在視網膜上形成清晰的物像...
2026-07-20
冬天為什麼适合戀愛
冬天為什麼适合戀愛
冬天來了,大街小巷都充滿了甜蜜溫暖的氣息,有街邊的烤紅薯攤飄出陣陣香氣、有手裡暖暖的奶茶捂熱了手和心,也有牽着手的情侶讓人感到一陣甜(xian)蜜(mu)。奇怪,為什麼總感覺一到冬天,街上的情侶就變多了?
2026-07-20
緻命的危險吉他譜
緻命的危險吉他譜
,
2026-07-20
家中進兩鳥無災也有禍
家中進兩鳥無災也有禍
家中進兩鳥無災也有禍?導讀:農村俗語“兩鳥進宅,無禍也有災”,哪兩種鳥呢?老話有道理嗎?,接下來我們就來聊聊關于家中進兩鳥無災也有禍?以下内容大家不妨參考一二希望能幫到您!家中進兩鳥無災也有禍導讀:農村俗語“兩鳥進宅,無禍也有災”,哪兩種鳥...
2026-07-20
臨沂市蘭陵縣二手房出售
臨沂市蘭陵縣二手房出售
臨沂市蘭陵縣二手房出售?21世紀不動産小區:星城國際,今天小編就來說說關于臨沂市蘭陵縣二手房出售?下面更多詳細答案一起來看看吧!臨沂市蘭陵縣二手房出售21世紀不動産小區:星城國際樓層:5/6面積:116.5平裝修:精裝戶型:3—2—1價格;...
2026-07-20
Copyright 2023-2026 - www.tftnews.com All Rights Reserved