Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to convert decimal to hexadecimal

Posted By: Lujza Fischer     Category: C Programming     Views: 8220

Write a program to convert decimal to hexadecimal.

Code for Program to convert decimal to hexadecimal in C Programming

#include<stdio.h>
#include<conio.h>
int i=0,bin[100];
void main()
{
    int j=0;
    int read(),destobin();
    clrscr();
    j=read();
    destobin(j);
    getch();
}

int read()
{
    int num;
    printf("\n PLEASE ENTER THE VALUE IN DECIMAL ( 0 - 15 ): ");
    scanf("%d",&num);
    return(num);
}

int destobin(int j)
{
    for(i=0;j>0;i++)
    {
        bin[i]=j%16;
        j=j/16;
    }

    i--;
    printf("\nDECIMAL TO HEXADECIMAL CONVERSION IS \t");
    for(;i>=j;i--)
    {
        if(bin[i]==10)
                printf("A");
        elseif(bin[i]==11)
                printf("B");
        elseif(bin[i]==12)
                printf("C");
        elseif(bin[i]==13)
                printf("D");
        elseif(bin[i]==14)
                printf("E");
        elseif(bin[i]==15)
                printf("F");
        else
            printf("%d",bin[i]);
    }
}
  
Share: 


Didn't find what you were looking for? Find more on Program to convert decimal to hexadecimal Or get search suggestion and latest updates.

Lujza Fischer
Lujza Fischer author of Program to convert decimal to hexadecimal is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in C Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!