Decimal to hex conversion using function

Program:

#include<stdio.h>
void dec2hex(int);
int main()
{
int dec;
printf("Enter Positive Integer Number: ");
scanf("%d",&dec);
dec2hex(dec);
return 0;
}
void dec2hex(int m)
{
    int i=0,j;
    char hex[10],store[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    while(m>0)
    {
    hex[i]=store[m%16];
    m=m/16;
    i++;
}
for(j=i-1;j>=0;j--)
{
printf("%c",hex[j]);
}
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...