Skip to main content

Posts

Showing posts with the label dec to bin in c program with example

C Program to Convert Decimal to Binary, Easy Logic to Convert Decimal to Binary in C Language

C Program to Convert Decimal to Binary, Easy Logic to Convert Decimal to Binary in C Language : Example : How to Convert Decimal Number to Binary in C with explanations given below :- #include<stdio.h> #include<conio.h> void main() { int q[50],i,a,n,count=0; clrscr(); printf("\nEnter a Decimal Number :"); scanf("%d",&n); for(i=0 ; n>0 ; i++) { a = n%2; /* storing remainter part, eg a=7%2 then a=1 ie 3. 1 */ q[i] = a; n = n/2; /* storing integer part, eg a=7/2 then a=3 ie 3 .1 */ count++; } printf("\nThe Conversion is given below :\n"); for(i=0 ; i < count ; i++) printf("%d",q[i]); getch(); } /* if we enter a decimal number as 7 the result will be 111, if 5 then 101 */