0

You are given two positive integers L and R. Now print the prime numbers between L to R.

Note: Assume that 1 is a prime number

Input Format

The first line will contain T, the number of test cases. Each test case contains two positive integer L and R Constraints

0 < T <= 20 1 <= L,R <= 100 and where L < R Output Format

Print the prime numbers between L to R.

int main()
{
    int t, i, j;
    scanf("%d", &t);
    for (i = 0; i < t; i++) {
        int l, r;
        scanf("%d %d\n", &l, &r);

        while (l < r) {
            for (j = 2; j < l / 2; j++) {
                if (l % j != 0) {
                    printf("%d ", l);
                }
                l += 1;
            }
        }
    }
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    return 0;
}

It takes input but doesnt return any value. I tried and could not fix it. Can anyone explain what is wrong with the code? And to offer suggestions to fix it please. Thanks.

mch
  • 9,424
  • 2
  • 28
  • 42
mysha
  • 1
  • 1
  • If the numbers are really less than 100, you can use `if (i ==2 || i == 3 || i == 5 || i ==7 || ((i % 2) && (i % 3) && (i % 5)&&(i%7)))` – mch Dec 29 '22 at 10:04
  • I'd suggest to explain to your [rubber duck](https://en.m.wikipedia.org/wiki/Rubber_duck_debugging) what's going on in the loop. Try it on paper. – Bob__ Dec 29 '22 at 11:09

0 Answers0