Thursday, January 21, 2016

Conversion of Decimel to Binary in C Programming

#include <stdio.h>
//decimel to binary

int main()
{ int i;
scanf("%d",&i);
while(i--)
{

  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");

 }
  return 0;
}

No comments:

Post a Comment

Thank you for commenting. Please wait for response :)