Multiple system conversion

xiaoxiao2021-03-06  61

/ * Name: Bodh.c Author: X-Bit Description: Decoction, Binary, Octa, Hexadecimal Conversion Date: 04/22/2004 CopyRight: x-bit@163.com*/

/ * # include * / # include #define m 100 / *********************************** ***************************************************** / VOID MENU (); int getselect (); void iOS (int SELECT ); void Exchange (long n, int base); / ******************************************* *********************** /

Int main () {menu (); while (1) {iOS (GetSelect ()); Printf ("/ n");}

Return 0;}

/ ************************************************** *********** / VOID Exchange (long n, int base) {int Arr [m]; int i = 0;

DO {Arr [i ] = n% base; n / = base;} while (n); / ********************************** ******************************************* / DO {Switch (Arr [- i]) {Case 10: Printf ("a"); Break; Case 11: Printf ("b"); Break; Case 12: Printf ("c"); Break; Case 13: Printf ("d"); Break; Case 14: Printf "E"); Break; Case 15: Printf ("f"); Break; default: Printf ("% d", arr [i]);}} while (i);

RETURN;} / ********************************************************* *************** / VOID MENU () {printf ("********************************* *************** / n "); Printf (" * 0. quit; * / n "); printf (" * 1. binary to oct, decimal and hex; * / n "); Printf (" * 2. Oct to binary, decimal and hex; * / n "); Printf (" * 3. Decmial to binary, oct and hex; * / n "); printf (" * 4. HEX to Binary, Oct and Decimal; * / N "); Printf (" * hex: 12af; Oct: 17 * / n "); Printf (" ************************* *************** / n ");} / ****************** **************************************************** / INT GetSelect () {int Sel; do {printf ("Enter a choice (0, 1, 2, 3, 4):"); Scanf ("% D", & SEL); if (! SEL) EXIT (1);} while (SEL! = 1 && SEL! = 2 && SEL! = 3 && SEL! = 4); returnide} / ********************************** ******************************************** / VOID iOS (int result) {Int Num, base;

Switch (select) {casse 1: / ********************* / Printf ("Please Do Another: 2-3 / N"); Break; Case 2: Printf ("Enter A Oct Number:"); Scanf ("% O", & NUM); do {printf ("Enter the base (2, 8, 10, 16):"); scanf ("% D ", & base);} while (NUM, BASE); Break; Case 3: Printf (" Enter A Decimal Number: "); Scanf ("% D ", & NUM); Printf (" Enter Thae Base (2, 8, 10, 16): "); Scanf ("% O ", & Num); do {printf (" Enter the base (2, 8, 10, 16): "); scanf ("% D ", & base); exchange (num, base); Break; Case 4: Printf (" Enter A HEX Number: "); Scanf ("% X ", & Num); Printf (" Enter THE Base (2, 8, 10, 16): "); Scanf ("% O ", & Num); do {printf (" Enter the base (2, 8, 10, 16): "); scanf ("% D ", & base);} while (!, base); Break;} return;

转载请注明原文地址:https://www.9cbs.com/read-108231.html

New Post(0)