Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created February 5, 2015 05:34
Show Gist options
  • Select an option

  • Save shohan4556/5724b20cd15e719f6a28 to your computer and use it in GitHub Desktop.

Select an option

Save shohan4556/5724b20cd15e719f6a28 to your computer and use it in GitHub Desktop.
quora 1593 help
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define N 20000000
char num[N];
int binary(int n);
int main()
{
int n,count,a,i,j,t;
scanf("%s",num);
for(i=0;num[i]!='\0';i++){
t=num[i]-'0'; // my problem is there it
a=binary(t);
printf("%d ",a);
}
printf("\n");
return 0;
}
int binary(int n)
{
int dstinatb=2,numb=10,po=0;
int res=0;
while(n)
{
res=res+n%dstinatb*pow(numb,po++);
n=n/dstinatb;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment