C program to covert Hexadecimal to Decimal.

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int decnum=0, rem, i=0, len=0;
    char hexnum[20];
    printf("Enter any Hexadecimal Number: ");
    scanf("%s", hexnum);
    while(hexnum[i]!='\0')
    {
        len++;
        i++;
    }
    len--;
    i=0;
    while(len>=0)
    {
        rem = hexnum[len];
        if(rem>=48 && rem<=57)
            rem = rem-48;
        else if(rem>=65 && rem<=90)
            rem = rem-55;
        else
        {
            printf("\nInvalid Hexadecimal digit");
            getch();
            return 0;
        }
        decnum = decnum + (rem*pow(16, i));
        len--;
        i++;
    }
    printf("\nDecimal Value = %d", decnum);
    getch();
    return 0;
}
C program to covert Hexadecimal to Decimal. C program to covert Hexadecimal to Decimal. Reviewed by on December 22, 2019 Rating: 5

No comments:

Powered by Blogger.