脚本实现进制转换问题?
小白急求大神:实现十进制转换三十四进制,只要实现单独的转换即可(转换范围要求无限大);不能有函数;我没办法实现无函数转换;
#include <stdio.h> #include <string.h> #include <ctype.h> #define MAX 1000 #define SYS 34 //最多36进制 const char strSYS[37] = {"0123456789abcdefghijklmnopqrstuvwxyz"}; int main(int argc, char *argv[]) { char strData[MAX]={"23789756567879787089746754456734657877659879790982354536658762134512455787697809870989809809824214124214214134"}; int DataInt[MAX]; int OutInt[MAX]; int strDatalen = strlen(strData); //不考虑负数,小数 ,感觉没bug,反正就这个意思 for(int i=0;i<strDatalen;i++) { DataInt[i]= strData[i]-'0'; } int Numerator=0,Remainder,Quotient; int OutIntCount = 0; bool falg = true; while(falg) { falg =false; for(int i=0;i<strDatalen;i++) { Numerator = Numerator*10+ DataInt[i]; Remainder = Numerator%SYS; Quotient = Numerator/SYS; DataInt[i] = Quotient; Numerator = Remainder; if(Quotient)falg =true; } Numerator= 0; OutInt[OutIntCount++] = Remainder; // printf("%d",Remainder); } for(int i=OutIntCount-1;i>=0;i--) { printf("%c",strSYS[OutInt[i]] ); } printf("\n"); return 0; }