0
The exercise asks the program to read an N number and print the N-esimo given prime number. Ex: I enter N = 3. The program will have to print The third prime number, which is 5. Other examples: N-esimo(2) = 3, N-esimo(5) = 11. I did the following:
void nesimo_primo(int n)
{
int a, primo, div, nesimo;
primo = 0;
a = 1;
if(n == 1)
nesimo = 2;
else
{
for(nesimo = 3; nesimo <= 1000; nesimo++)
{
for(div = 2; div <= nesimo/2; div++)
{
if(nesimo%div != 0)
primo++;
if(primo == 1)
a = a + 1;
}
if(a == n)
break;
}
}
printf("N-esimo(%d) = %d\n", a, nesimo);
}
I wonder if logic makes sense and what might be wrong for the program not working properly.
if any of the answers solved your problem, you can click on V next to the answer to mark your question as answered.
– Brumazzi DB