C program to convert decimal into binary.

 

01  #include<stdio.h>
02 #include<stdlib.h>
03
04 int main()
05 {
06 int i=0,j;
07 int dNum;
08 int bArr[20];
09
10 printf("Enter Decimal No. : ");
11 scanf("%d",&dNum);
12
13 if(dNum==0)
14 {
15 printf("Binary string is 0");
16 exit(0);
17 }
18
19 while(dNum>0)
20 {
21 bArr[i]=dNum%2;
22 dNum=dNum/2;
23 i++;
24 }
25
26 printf("Binary string is ");
27
28 for(j=i-1;j>=0;j--)
29 {
30 printf("%d",bArr[j]);
31 }
32
33 return 0;
34 }
 
 OUTPUT :

Enter Decimal N. : 55
Binary string is 110111

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.