本文介绍了hexa到dec转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
  int dechex=0;
  int hexdec;
  printf("Please enter your input in Hexadecimal form: ");

  hexdec = getchar();

  while(hexdec != '\n')
  {
    if('0' <= hexdec && hexdec <= '9')
    {
      dechex = dechex * 16;
      dechex = dechex + (hexdec - '0');
      break;
    }
    else if('A' <= hexdec && hexdec <= 'F')
    {
      dechex = dechex * 16;
      dechex = dechex + (hexdec - 'A')+10;
      break;
    }
    else if('a' <= hexdec && hexdec <= 'f')
    {
      dechex = dechex * 16;
      dechex = dechex + (hexdec - 'a')+10;
      break;
    }
    else
    {
      dechex=0;
    }

    hexdec = getchar();
  }
  
  printf("\nYour input number in decimal form is %d",dechex);
}





请帮帮我们我们错了o / p ....



please help me guys am getting wrong o/p ....

thanku but output is giving
input-5 ;output-5
input-fff;output-15
input-aa;output-10
why this happens







请帮助大家




please help guys

推荐答案

void main()
{
  int dechex = 0;
  // ...
}




这篇关于hexa到dec转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 08:18