C program to convert decimal to binary number.

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

Expected Output:
Enter an integer in decimal number system
57
 57 in binary number system is:
00000000000000000000000000111001

Post a Comment

Previous Post Next Post