0% found this document useful (0 votes)
90 views1 page

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views1 page

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
We take content rights seriously. If you suspect this is your content, claim it here.
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy