Đổi hệ

#include<stdio.h> #include<conio.h> #include<math.h> #include<string.h> void DOIHE(int value,char *KetQua,int coso) { int idx=0; while(value!=0) { int so= (value%coso); if(so<9) { KetQua[idx++]=so+48; } else if(so==10) { KetQua[idx++]='A'; } else if(so==11) { KetQua[idx++]='B'; } else if(so==12) { KetQua[idx++]='C'; } else if(so==13) { KetQua[idx++]='D'; } else if(so==14) { KetQua[idx++]='E'; } else if(so==15) { KetQua[idx++]='F'; } value/=coso; } KetQua[idx]='\0'; strrev(KetQua); } int ChuyenheSangSo(char *S) { int Lenth=strlen(S); int tong=0; for(int i=Lenth-1;i>=0;i--) { int So=S[i]-48; tong+=So*pow(2.0,i); } return tong; } int main() { char S[30]="11111010"; int k=ChuyenheSangSo(S); printf("%d",k); getch(); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.