資源描述:
《(c語(yǔ)言)10進(jìn)制轉(zhuǎn)換2,8,16進(jìn)制》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、(C語(yǔ)言)10進(jìn)制轉(zhuǎn)換2,8,16進(jìn)制作者:vinseven#include"stdio.h"#include"conio.h"#include"malloc.h"#include"windows.h"#defineElemTypeintvoidmenu();voidTenToTwo();voidTenToEight();voidTenToSixteen();voidInitStack(structsNode**HS);voidPush(structsNode**HS,ElemTypex);ElemTypePop
2、(structsNode**HS);ElemTypePeek(structsNode**HS);intEmptyStack(structsNode**HS);voidClearStack(structsNode**HS);intten;/*要輸入的10進(jìn)制數(shù)*/intx;/*把將要插入到棧中的元素暫時(shí)存進(jìn)x中*/structsNodehs;structsNode{ElemTypedata;structsNode*next;};voidmain(){menu();getch();}voidmenu(){charch
3、oice;intflag=1;while(1){printf("ttt________________________");printf("ttt1,10進(jìn)制轉(zhuǎn)換2進(jìn)制");printf("ttt2,10進(jìn)制轉(zhuǎn)換8進(jìn)制");printf("ttt3,10進(jìn)制轉(zhuǎn)換16進(jìn)制");printf("ttt0,退出");printf("ttt________________________");printf("t
4、tt請(qǐng)輸入編號(hào):");while(flag){fflush(stdin);choice=getch();switch(choice){case'1':{system("cls");TenToTwo();flag=0;break;}case'2':{system("cls");TenToEight();flag=0;break;}case'3':{system("cls");TenToSixteen();flag=0;break;}case'0':{printf("ttt按任意鍵退出");getch()
5、;exit(0);}default:{printf("ttt無(wú)此選項(xiàng)可選!請(qǐng)重新輸入!");flag=1;break;}}}system("cls");flag=1;}}/*10進(jìn)制轉(zhuǎn)換2進(jìn)制界面*/voidTenToTwo(){printf("ttt________________________");printf("ttt10進(jìn)制轉(zhuǎn)換2進(jìn)制界面");printf("ttt________________________");printf("
6、ttt請(qǐng)輸入10進(jìn)制數(shù):");scanf("%d",&ten);while(ten!=0){x=ten%2;Push(&hs,x);ten=ten/2;}printf("ttt二進(jìn)制數(shù)為:");while(!EmptyStack(&hs))printf("%d",Pop(&hs));getch();}/*10進(jìn)制轉(zhuǎn)換8進(jìn)制界面*/voidTenToEight(){printf("ttt________________________");printf("ttt10進(jìn)制轉(zhuǎn)換8進(jìn)
7、制界面");printf("ttt________________________");printf("ttt請(qǐng)輸入10進(jìn)制數(shù):");scanf("%d",&ten);while(ten!=0){x=ten%8;Push(&hs,x);ten=ten/8;}printf("ttt八進(jìn)制數(shù)為:");while(!EmptyStack(&hs))printf("%d",Pop(&hs));getch();}/*10進(jìn)制轉(zhuǎn)換16進(jìn)制界面*/voidTenToSixteen(){in
8、ttemp;printf("ttt________________________");printf("ttt10進(jìn)制轉(zhuǎn)換16進(jìn)制界面");printf("ttt________________________");printf("ttt請(qǐng)輸入10進(jìn)制數(shù):");scanf("%d",&ten);while(ten