0% found this document useful (0 votes)
82 views

C Program To Convert Decimal To Binary

This C program converts a decimal number into another base by repeatedly dividing the number by the base and storing the remainders. It takes a decimal number and base as input, divides the number by the base to get a quotient and remainder at each step, converts the remainders to ASCII characters and stores them in reverse order in an output array, then prints the output array to display the number in its new base representation.

Uploaded by

SD
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

C Program To Convert Decimal To Binary

This C program converts a decimal number into another base by repeatedly dividing the number by the base and storing the remainders. It takes a decimal number and base as input, divides the number by the base to get a quotient and remainder at each step, converts the remainders to ASCII characters and stores them in reverse order in an output array, then prints the output array to display the number in its new base representation.

Uploaded by

SD
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>
int main()
{
long decimalnum, quotient;
int i, j = 0,remainder,base;
char output[100];
printf("Enter decimal number and base : \n ");
scanf("%ld%d", &decimalnum,&base);
quotient = decimalnum;
while (quotient != 0)
{
remainder = quotient % base;
if (remainder < 10)
output[j++] = 48 + remainder;
else
output[j++] = 55 + remainder;
quotient = quotient / base;
}

// display integer into character


for (i = j; i >= 0; i--)
printf("%c", output[i]);
printf("\n");
return 0;
}

You might also like