W.A.P in c to convert decimal to
hexadecimal no.
#include<stdio.h>
#include<conio.h>
void
hexa(long);
void
main()
{
long
int n;
clrscr();
printf("Conversion
from Decimal to Hexadecimal\n");
printf("\n\nEnter
the decimal number: ");
scanf("%ld",&n);
printf("\n\nThe
hexa decimal no is:- ");
hexa(n);
getch();
}
void
hexa(long n)
{
long
i;
if(n>0)
{
i=n%16;
n=n/16;
hexa(n);
if(i>=10)
{
switch(i)
{
case
10: printf("A"); break;
case
11: printf("B"); break;
case
12: printf("C"); break;
case
13: printf("D"); break;
case
14: printf("E"); break;
case
15: printf("F"); break;
}
}
else
printf("%ld",i);
}
}
output:
Conversion
from Decimal to Hexadecimal
Enter the
decimal number:720
hexadecimal equvalient:2D0
No comments:
Post a Comment