You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
programming-examples/c/Basic/C program to Convert Decima...

27 lines
702 B
C

/*
* C program to Convert Decimal to Hexadecimal
*/
#include <stdio.h>
int main()
{
long decimalnum, quotient, remainder;
int i, j = 0;
char hexadecimalnum[100];
printf("Enter decimal number: ");
scanf("%ld", &decimalnum);
quotient = decimalnum;
while (quotient != 0)
{
remainder = quotient % 16;
if (remainder < 10)
hexadecimalnum[j++] = 48 + remainder;
else
hexadecimalnum[j++] = 55 + remainder;
quotient = quotient / 16;
}
// display integer into character
for (i = j; i >= 0; i--)
printf("%c", hexadecimalnum[i]);
return 0;
}