Prime number generator in C I have to print numbers between two limits n and m, t times.
I created t variable that stores a number of test cases.
Outer for loop iterates for every test cases.
Inner for loop prints primes from m to n.
Code
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
 
int is_prime(int);
 
int main(void) {
    int t, m, n;
    scanf(&quot;%d&quot;, &amp;t);
    for (int i = 0; i &lt; t; i++) {
        scanf(&quot;%d %d&quot;, &amp;m, &amp;n);
        for (int j = m; j &lt;= n; j++) {
            if (is_prime(j)) {
                printf(&quot;%d\n&quot;, j);
            }
        }
        if (i &lt; t - 1) printf(&quot;\n&quot;);
    }
 
    return 0;
}
 
int is_prime(int num) {
    if (num &lt;= 1) return 0;
    for (int i = 2; i * i &lt;= num; i++) {
        if (num % i == 0) {
            return 0;
        }
    }
    return 1;
}

Problem: http://www.spoj.com/problems/PRIME1/
Can I have review?
The only even prime number is two, so with a little extra coding you can ignore even numbers in the for loop.  For even more speed use a sieve, though maybe save that for when you get a 'TLE' failure.

A more formal code layout would be good as well, your if statements need expanding to include {...}.  More vertical space (blank lines) a well as explanatory comments help.  When you come back to your old code six months later you will thank yourself.

I prefer to set 0 and 1 as FALSE and TRUE to make code easier to read YMMV.

int is_prime(int num) {
  if (num &lt;= 1) {
    return FALSE;
  }

  // Even numbers.
  if (num % 2 == 0) {
    return num == 2;  // 2 is the only even prime.
  }

  // Odd numbers.
  // Start loop at 3 and step 2 to skip even divisors.
  for (int i = 3; i * i &lt;= num; i += 2) {
    if (num % i == 0) {
        return FALSE;
    }
  }
  return TRUE;
}