Friday, 10 July 2015

Write C program to Decimal to Binary Conversion

1:  #include <stdio.h>  
2:  int main()  
3:  {  
4:   int n, c, k;  
5:   printf("Enter an integer in decimal number system\n");  
6:   scanf("%d", &n);  
7:   printf("%d in binary number system is:\n", n);  
8:   for (c = 31; c >= 0; c--)  
9:   {  
10:    k = n >> c;  
11:    if (k & 1)  
12:     printf("1");  
13:    else  
14:     printf("0");  
15:   }  
16:   printf("\n");  
17:   return 0;  
18:  }  

No comments:

Post a Comment