title: How to find the sum of Prime Numbers in C within a given range?
body: <p>I'm very new to programming and I was asked to find the sum of prime numbers in a given range, using a <code>while</code> loop. If The input is 5, the answer should be <code>28 (2+3+5+7+11)</code>. I tried writing the code but it seems that the logic isn't right.</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      int range,test;
      int sum = 2;
      int n = 3;
      printf("Enter the range.");
      scanf("%i",range);
      while (range &gt; 0)
      {
          int i =2;
          while(i&lt;n)
          {
              test = n%i;
              if (test==0)
              {
               goto end;
              }
                    i++;
          }
          if (test != 0)
          {
              sum = sum + test;
              range--;
          }
          end:
                    n++;
      }
      printf("The sum is %i",sum);
      return 0;
  }
  </code></pre>
  
  <p>It would be nice if you could point out my mistake and possibly tell me how to go about from there.</p>