answersLogoWhite

0


Best Answer

Inorder to display a binary value of a number in C language, 1st create an integer array of size n. Then inside a for loop divide that number by 2 repeatedly and store the remainder in that array from 0 to n. The remainder is always a 0 or 1. Finally when the number itself reaches 1, put this 1 also in your array. Then display it by printing the array from n-1 to 0.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int temp=0, num, mul=1, sum=0;

clrscr();

printf("enter the no:");

scanf("%ld" , &num);

while(num>0)

{

temp=num%2;

temp=mul * temp;

sum += temp;

mul *=10;

num /=2;

}

printf("%d", sum);

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to print binary equivalent of given integer value in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to subtract integer y from integer x?

x -=y;


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Conversion of decimal to binary in fortran?

This is not a perfect program, but it will get you started in the right direction. Works for any INTEGER up to "some" power of 2 (decimals kill the program). PROGRAM binary IMPLICIT NONE INTEGER remainder, quotient, n, int_input, answer REAL input, dec_input WRITE(*,*) 'Input a number to convert to binary' READ(*,*) input int_input = input dec_input = input - int_input dec_input = abs(dec_input) quotient = abs(input) DO WHILE (dec_input==0) n = 0 answer = 0 DO WHILE (quotient&gt;1) remainder = mod(quotient,2) quotient = quotient/2 answer = answer+remainder*10.**n n = n+1 END DO IF (input&lt;0) answer = -answer answer = answer + quotient*10.**n WRITE(*,"(a,i31)") 'Your answer in binary is:',answer END DO END PROGRAM binary


Write a program of binary heap in c or c language?

to implement operations on binary heap in c


Write a program in c language to diaplay the given integer in binary using while loop?

int num = 1245; //Number to display in binary int pos = log(1425.0f) / log(2.0f) + 1; //calculate # of binary digits while (--pos &gt;= 0) printf("%d", num &amp; (1 &lt;&lt; pos) ? 1 : 0); printf("\n");


Write a C program that takes a binary file as input and finds error check using different mechanisms?

write a c program that takes a binary file as input and finds error check using different mechanisms.


What is -041666 as a fraction?

-041666 is an integer and not a fraction so it makes little sense to write it as a fraction. But, if you must, one equivalent is -41666/1.-041666 is an integer and not a fraction so it makes little sense to write it as a fraction. But, if you must, one equivalent is -41666/1.-041666 is an integer and not a fraction so it makes little sense to write it as a fraction. But, if you must, one equivalent is -41666/1.-041666 is an integer and not a fraction so it makes little sense to write it as a fraction. But, if you must, one equivalent is -41666/1.


How do you convert fractional decimal numerals in binary?

Steps to convert fractional decimal to binary: 1.Multiply the number fractional part) successively by 2 and note the integer part of product. 2.Repeat the process till the fractional part becomes 0 or required accuracy is reached. 3.Binary equivalent of fractional part are the carries i.e. integer which is noted separately. Write down these carries from top to bottom. e.g. Conversion of 0.75 to binary 0.75*2=1.50 1 0.50*2=1.00 1 ans==&gt; (0.11)


How do you Write 810 in simplest form and then write another equivalent fraction for 810?

810 is an integer and so it is in its simplest form. An equivalent fraction is any number of the form (810*n)/n where n is a non-zero integer.


Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equiavalent?

Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equivalent?


How do you get the subnet of 220.200.190.0 and how do you write it out in binary?

To get the subnet of an IPv4 address you need to know the subnet mask. To write the IP address in binary, simply convert each octet to its binary equivalent and remove the periods (dots). Thus 220.200.190.0 becomes 11011100110010001011111000000000.


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.