首页
/
每日頭條
/
圖文
/
c語言如何将數字從小到大排列
c語言如何将數字從小到大排列
更新时间:2026-07-27 12:22:36

題目要求:

輸入一個數字序列{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
推荐阅读
vivoy52s移動版和全網通
vivoy52s移動版和全網通
vivoy52s移動版和全網通?憑借纖薄機身、時尚外觀以及超清影像系統等特點的加持,vivoY系列在年輕用戶群體中的人氣一直居高不下全新推出的vivoY52s将于明日正式開售,8GB128GB售價為1798元,現在小編就來說說關于vivoy...
2026-07-27
增值稅稅收分類編碼怎麼修改
增值稅稅收分類編碼怎麼修改
一是不征收增值稅的項目用于納稅人收取款項但未發生銷售貨物、應稅勞務、服務、無形資産或不動産的情形。商品和服務稅收分類與編碼的“6未發生銷售行為的不征稅項目”。二是不征稅項目下設:601“預付卡銷售和充值602“銷售自行開發的房地産項目預收款...
2026-07-27
靳夢佳中餐廳第幾季
靳夢佳中餐廳第幾季
《中餐廳》的播出已經接近尾聲了,但是對節目中唯一的新人靳夢佳,這位“洗碗小妹”,很多人都知之甚少,作為一位不為人知的新人,能參加這樣一檔節目,引起了很多人的猜測。靳夢佳,24歲,靳夢佳畢業于武漢大學,2012年曾參加星姐選舉比賽,後簽約芒果...
2026-07-27
怎麼樣可以學會冥想
怎麼樣可以學會冥想
冥想,要一動不動地坐着嗎?是不是冥想練習中,不能有任何想法啊?很多初級冥想練習者,或者沒經過正确引導的瑜伽練習者,包括瑜伽老師,都對冥想的認識很模糊,沒有清晰的認識。所以會感覺冥想不知在“做什麼”,引導不知要“說什麼”。冥想時,要一動不動地...
2026-07-27
月皎皎星漢迢迢
月皎皎星漢迢迢
,
2026-07-27
Copyright 2023-2026 - www.tftnews.com All Rights Reserved