#include#defineMAX20typedefstruct{intdata[MAX];inttop;}SeqStack;SeqStack*Init(){SeqSt">
C語言 順序棧實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為二進(jìn)制,八進(jìn)制,十六進(jìn)制

C語言 順序棧實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為二進(jìn)制,八進(jìn)制,十六進(jìn)制

ID:44171322

大?。?6.12 KB

頁數(shù):3頁

時(shí)間:2019-10-19

C語言 順序棧實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為二進(jìn)制,八進(jìn)制,十六進(jìn)制_第1頁
C語言 順序棧實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為二進(jìn)制,八進(jìn)制,十六進(jìn)制_第2頁
C語言 順序棧實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為二進(jìn)制,八進(jìn)制,十六進(jìn)制_第3頁
資源描述:

《C語言 順序棧實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為二進(jìn)制,八進(jìn)制,十六進(jìn)制》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。

1、運(yùn)行結(jié)果:代碼:#include#include#defineMAX20typedefstruct{intdata[MAX];inttop;}SeqStack;SeqStack*Init(){SeqStack*s;s=(SeqStack*)malloc(sizeof(SeqStack));s->top=-1;returns;}voidDestroy(SeqStack*s){free(s);}boolIsFull(SeqStack*s){return(s->top==MAX-1)?true:false;}boolIsEmpty(SeqSta

2、ck*s){return(s->top==-1)?true:false;}voidPush(SeqStack*s,inta){if(IsFull(s)){printf("Thestackisfull,failedtopush!");return;}s->top++;s->data[s->top]=a;}intPop(SeqStack*s){inte;if(IsEmpty(s)){printf("Thestackisempty,failedtopop!");returnNULL;}e=s->data[s->top];s->top--;returne;}intReadTo

3、p(SeqStack*s){returns->data[s->top];}voidPrint(SeqStack*s){inttemp=s->top;if(IsEmpty(s)){printf("Thestackisempty!");return;}printf("轉(zhuǎn)換后的結(jié)果:");while(temp>=0){if(s->data[temp]<10)printf("%d",s->data[temp]);else{if(s->data[temp]=10)printf("a");elseif(s->data[temp]=11)printf("b");elseif(s->

4、data[temp]=12)printf("c");elseif(s->data[temp]=13)printf("d");elseif(s->data[temp]=14)printf("e");elseprintf("f");}temp--;}printf("");}intmain(){intm,c,d,n;SeqStack*s;s=Init();printf("請輸入要轉(zhuǎn)換的十進(jìn)制數(shù):");scanf("%d",&m);printf("");printf("請輸入轉(zhuǎn)換進(jìn)制:");printf("******************************"

5、);printf("*請選擇一個(gè)你要轉(zhuǎn)換的進(jìn)制*");printf("*1.二進(jìn)制*");printf("*2.八進(jìn)制*");printf("*3.十六進(jìn)制*");printf("******************************");scanf("%d",&d);printf("");if(d==1)n=2;elseif(d==2)n=8;elseif(d==3)n=16;elseprintf("輸入有誤!");while(m){c=m%n;m=m/n;Push(s,c);}Print(s);Destroy(s);}

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動(dòng)畫的文件,查看預(yù)覽時(shí)可能會(huì)顯示錯(cuò)亂或異常,文件下載后無此問題,請放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負(fù)責(zé)整理代發(fā)布。如果您對(duì)本文檔版權(quán)有爭議請及時(shí)聯(lián)系客服。
3. 下載前請仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時(shí)可能由于網(wǎng)絡(luò)波動(dòng)等原因無法下載或下載錯(cuò)誤,付費(fèi)完成后未能成功下載的用戶請聯(lián)系客服處理。