Find prime numbers in specific interval in specific amount of test cases.
Example is below: Input:
2
1 10
3 5
Output:
2
3
5
7
3
5
Notice the little space between the answer also.
here's my code:
#include <iostream>
#include <cmath>
void prime (int x, int y);
using namespace std;
int main()
{
int t, x[10], y[10];
cin >> t;
for (int i = 0; i < t; i++)
//for (int j = 0; j < t; j++)
cin >> x[i] >> y[i];
while (t > 0){
for (int i = 0; i < t; i++)
prime(x[i], y[i]);
t--;
}
}
void prime(int x, int y){
bool prime = true;
for (int i = x; i <= y; i++){
for (int j = 2; j <= sqrt(i); j++){
prime = true;
if (i % j == 0)
prime = false;
}
if (prime == true)
cout << i << endl;
}
cout << endl;
}
Here's the output I get when I use the same input.
1
2
3
5
7
10
3
5
1
2
3
5
7
10
What am I doing wrong?