Pages

Friday, 12 June 2020

Decimal to Binary conversion C language

Q : Write a C Program using function to print equivalent binary number of decimal number input by keyboard ?

Answer : 

#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Decimal to Binary conversion
  ##########################*/
void main()
{
     int d,b,ar[10],i;
     clrscr();
     printf("Enter number> ");
     scanf("%d",&d);
     i=0;
     while(d>0)
     {
          ar[i]=d%2;
          d=d/2;
          i++;
     }
     i--;
     while(i>=0)
     {
          printf("\t%d",ar[i]);
          i--;
     }
     getch();
}

No comments:

Post a Comment