Finding prime number between 1 and N
<p>In fact my teacher has passed the program that calculates the prime numbers from 1 to N. But I did not understand some things in the code and would like to help.</p>

<p>In line 18 we have the following: <code>for(j=2; j&lt;=i/2; j++)</code>, because j was divided by 2? and why j start in 2? should not start i and j on 1?</p>

<pre><code>#include &lt;stdio.h&gt;

int main() {
    int i, j, n, isPrime; //isPrime is used as flag variable

    /* Reads upper limit to print prime */
    printf("Find prime numbers between 1 to : ");
    scanf("%d", &amp;n);

    printf("\nAll prime numbers between 1 to %d are:\n", n);

    /* Finds all Prime numbers between 1 to n */
    for(i=2; i&lt;=n; i++) {
        /* Assume that the current number is Prime */
        isPrime = 1;

        /* Check if the current number i is prime or not */
        for(j=2; j&lt;=i/2; j++) {
            /*
             * If i is divisible by any number other than 1 and self
             * then it is not prime number
             */
            if(i%j==0) {
                isPrime = 0;
                break;
            }
        }

        /* If the number is prime then print */
        if(isPrime==1) {
            printf("%d is Prime number\n", i);
        }
    }

    return 0;
}
</code></pre>