Saturday, April 10, 2021

20.47. Write a program that read any hexadecimal number and display equivalent decimal number.

#include<stdio.h>
#include<conio.h> 
#include<string.h>
void main ()
{
char *st;
int i,n,l;
clrscr();
st=(char *)malloc(sizeof(char)*100);
printf ("Enter any Hexadecimal number: ");
scanf("%s",st);
n=0;
l=strlen(st);
for(i=0; i<1; i++)
if(*st[i]>='0' && *st[i]<='9'
n=n*16+st[i]-48;
else if(*st[i]>='A' && *st[i]<='F'
n=n*16+st[i]-55;
else if(*st[i]>='a' && *st[i]<='f'
n=n*16+*st[i]-87;
printf("Eqivalent decimal number is: %ld",n);
getch ();
}

No comments:

Post a Comment