title: How to check prime number using user-defined function?
body: <p>I know what a prime number is. But I am unable to solve the logic using C. I tried as below:</p>
  
  <pre><code>main()
  {
      int a, b, c, n=0, start, end, sum=0;
      printf("Range Start From: ");
      scanf("%d", &amp;start);
      printf("End of Range: ");
      scanf("%d", &amp;end);
  
      for(a=start;a&lt;=end;a++)
      {
          for(b=2;b&lt;=a/2;b++)
          {
              if(a%b==0)
              {
                  c=0;
                  break;
              }
          }
          if(c==1)
          {
              sum+=a;
              n++;
          }
      }
      printf("The Sum of Primes is: %d\nTotal primes: %d", sum, n);
      getch();
      return 0;
  }
  </code></pre>