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

Post a Comment

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