title: Program to check whether a number can be expressed as a sum of two prime numbers
body: <p>I wrote the following program to check whether a given number can be expressed as a sum of two prime numbers. It compiles fine but does not work as expected. For eg, for input = 16, it displays that 16 cannot be expressed as a sum of two prime numbers. Also for eg, input = 5, it displays 5 = 3 + 2 rather than 5 = 2 + 3.</p>
  
  <pre><code>/* Program to check whether a number can be expressed as a sum of two prime numbers*/
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int prime(int x)
  {
      int fact=0,i;
      for(i=2;i&lt;x;i++)
      {
          if(x%i==0)
          {
              fact++;
              break;
          }
      }
      if (fact==0)
          return 1;
      else return 0;
  }
  int main()
  {
      int a,b,c,d,count=0;
      printf("Enter Number\n");
      scanf("%d",&amp;a);
      for(b=2;b&lt;(a+1)/2;b++);
      {
          c = prime(b);
          d = prime(a-b);
          if (c==1 &amp;&amp; d==1)
          {
              printf("%d = %d + %d\n",a,b,a-b);
              count++;
          }
      }
      if(count==0)
          {
              printf("%d cannot be expressed as sum of two prime numbers.\n",a);
          }
      return 0;
  }
  </code></pre>