Hello.
You must write a program that performs this translation. In C language. I started writing, but something is not being done.
#include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #include <stdio.h> int HEX_TO_DEC(char st[10]) { int i, s, k, p; s = 0; p = strlen(st) - 1; for (i = 0; st[i] != '\0'; i++) { switch (toupper(st[i])) { case 'A': k = 10; break; case 'B': k = 11; break; case 'C': k = 12; break; case 'D': k = 13; break; case 'E': k = 14; break; case 'F': k = 15; break; case '1': k = 1; break; case '2': k = 2; break; case '3': k = 3; break; case '4': k = 4; break; case '5': k = 5; break; case '6': k = 6; break; case '7': k = 7; break; case '8': k = 8; break; case '9': k = 9; break; case '0': k = 0; break; } s = s + k * pow(16, p); p--; } printf("%s", &s ") ; return 0; } void main() { char st[10]; char ch; scanf (" % s ", &st "); printf("Rezultant: n"); HEX_TO_DEC(st); }
Where is the mistake? Thank you in advance.