#define MAXLEN 10001 char * addBinary(char * a, char * b){ char* arr=(char*)calloc(MAXLEN+1,sizeof(char)); int right1=strlen(a)-1, right2=strlen(b)-1, flag=0, i, pst=MAXLEN, temp1, temp2; while(right1>=0 || right2>=0 || flag){ temp1=(right1>=0)?a[right1--] :'0'; temp2=(right2>=0)?b[right2--] :'0'; arr[--pst]='0'+(temp1-'0'+temp2-'0'+flag)%2; flag=(temp1-'0'+temp2-'0'+flag >= 2)?1 :0; } return arr+pst; }