Monday, 11 January 2016

C program to convert the Decimal value to Binary value

#include <stdio.h>
 
int main()
{
  int n, c, k;
 
  printf("Enter an integer in decimal number system:");
  scanf("%d", &n);
 
  printf("%d in binary number system is:", n);
 
  for (c = 31; c >= 0; c--)
  {
    k = n >> c;
 
    if (k & 1)
      printf("1");
    else
      printf("0");
  }
 
  printf("\n");
 
  return 0;
}

Output:
       Enter an integer in decimal number system:100
       100 in binary number system is:00000000000000000000000001100100

No comments:

Post a Comment