title: Function add two binary numbers in c++
body: <p>In c++, how I can write a program that read 2 binary numbers then print the result of addition, using a function to read the binary numbers each number has 4-bit, and using a function to add (binary 1, binary 2) ?!</p>
  
  <p>I find this program but I don't want it with arrays, I need it with only functions.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
  int a[4];
  int b[4];
  int carry=0;
  int result[5];
  
  
  a[0]=1;
  a[1]=0;
  a[2]=0;
  a[3]=1;
  
  b[0]=1;
  b[1]=1;
  b[2]=1;
  b[3]=1;
  
  for(int i=0; i&lt;4; i++)
  {
  
      if(a[i]+b[i]+carry==3)
      {
      result[i]=1;
      carry=1;
      }
      if(a[i]+b[i]+carry==2)
      {
      result[i]=0;
      carry=1;
      }
      if(a[i]+b[i]+carry==1)
      {
      result[i]=1;
      carry=0;
      }
      if(a[i]+b[i]+carry==0)
      {
      result[i]=0;
      carry=0;
      }
  
  
  }
  result[4]=carry;
  for(int j=4; j&gt;=0; j--)
  {
      cout&lt;&lt;result[j];
  
  }
  cout&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>