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 <stdio.h>
#include <stdlib.h>
int is_prime(int);
int main(void) {
int t, m, n;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d %d", &m, &n);
for (int j = m; j <= n; j++) {
if (is_prime(j)) {
printf("%d\n", j);
}
}
if (i < t - 1) printf("\n");
}
return 0;
}
int is_prime(int num) {
if (num <= 1) return 0;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return 0;
}
}
return 1;
}
Problem: http://www.spoj.com/problems/PRIME1/
Can I have review?