fgw_three is right.
When you store like this.The most significant digit is stored at code[0].Code:char code[15]; fgets(code,15,stdin);
Code:for(i=9;i>=0; i--) { if((i==9) && (toupper(*(code + i)) == 'x')) { value = 10; } else { value = (int)(*(code + i)-48); \\\By this Yor are moving from least signicant to most significant. } sum += value * (i+1);\\here you are multiplying with 10 with least significant,9 with.... so on.Your are doin opposite. }