write an algorithm,draw a flowchart and write its corresponding C program to convert a decimal number to its equivalent hexadecimal number.
Answers
Algorithm:
Step 1: Divide the original decimal number given in the question by 16
Step 2: Divide the quotient you get by 16
Step 3: Repeat step 2 until we get quotient equal to zero.
Code:
#include<stdio.h>
int main() {
long int decimalNumber,remainder,quotient;
int i=1,j,temp;
char hexadecimalNumber[100];
printf("Enter any decimal number: ");
scanf("%ld",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0) {
temp = quotient % 16;
//To convert integer into character
if( temp < 10)
temp =temp + 48; else
temp = temp + 55;
hexadecimalNumber[i++]= temp;
quotient = quotient / 16;
}
printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber);
for (j = i -1 ;j> 0;j--)
printf("%c",hexadecimalNumber[j]);
return 0;
}
Thank you for asking this question.
/*
* C program to Convert Decimal to Hexadecimal
*/
#include <stdio.h>
#include<conio.h>
int main()
{
long decim, quotient, remainder;
int i, j = 0;
char hexd[100];
printf("Enter decimal number: ");
scanf("%ld", &decim);
quotient = decim;
If there is any confusion please leave a comment below.