bet手机娱乐官网

怎样将十六进制转换为十进制 用递归的方法

2020-07-04 10:31栏目:主页 > bet手机娱乐官网 >

摘要:这里有个2 10 16互转的#include "stdio.h"#include "math.h"main(){ int error,i,j,k,number_b,number_d,temp;char type;char number_copy[60],number[60];error=1;number_d=0;printf("please choose type,1--Binery,2--Decimal,3--Hex\n");scanf("%c",......
这里有个2 10 16互转的 #include "stdio.h" #include "math.h" main() { int error,i,j,k,number_b,number_d,temp; char type; char number_copy[60],number[60]; error=1; number_d=0; printf("please choose type,1--Binery,2--Decimal,3--Hex\n"); scanf("%c",&type); while((type!='1')&&(type!='2')&&(type!='3')) { printf("type error,please input the type again\n"); scanf("%c",&type); } switch (type) { case '1': { printf("\nplease input the binery number:"); scanf("%s",number); while (error==1) { for(i=0;number[i]!='\0';i++) { if((number[i]!='0')&&(number[i]!='1')) { error=1; break; } else error=0; } if(error==0) break; else { printf("\nnumber error,pls input again:\n"); scanf("%s",number); } } for(i=i-1,j=0;i>=0;i--,j++) { number_d=(number[j]-48)*pow(2,i)+number_d; } printf("\nthe decimal number is:%d\nthe hex number is:%X",number_d,number_d); } break; case '2': { printf("\nplease input the decimal number:"); scanf("%s",number); while(error==1) { for(i=0;number[i]!='\0';i++) { if(number[i]<'0'||number[i]>'9') { error=1; break; } else error=0; } if(error==0) break; else { printf("\nnumber error,pls input again:\n"); scanf("%s",number); } } for(i=i-1,j=0;i>=0;i--,j++) { number_d=(number[j]-48)*pow(10,i)+number_d; } printf("\nthe hex number is:%X",number_d); for(i=0;number_d!=0;i++) { number[i]=number_d%2+48; number_d=number_d/2; } for(j=i-1,k=0;k<(i-1)/2+1;j--,k++) { temp=number[j]; number[j]=number[k]; number[k]=temp; } printf("\nthe binary number is:%s",number); } break; case '3': { printf("\nplease input the hex number:"); scanf("%s",number); while(error==1) { for(i=0;number[i]!='\0';i++) { if((number[i]>='0'&&number[i]
        

bet手机娱乐官网(http://www.tokyon.com

相关内容推荐: