Custom Search

Saturday 21 January 2012

Write a c program to convert decimal to binary

Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#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()
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...