Thursday, 26 October 2017

Decimal To Binary

#include<stdio.h>
int main(int argc,char *argv[])
{
int rem,i=1,bin=0,dec;
if(argc!=2)
exit(1);
dec=atoi(argv[1]);
while(dec!=0)
{
rem=dec%2;
dec=dec/2;
bin=bin+rem*i;
i=i*10;
}
printf("Expected new binary number %d",bin);
return 0;
}
Contributed by Priti Lohia

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. check your code once again its giving correct result. may be you have done some mistake.

      Delete

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...