The condition i==j+1
will not be true for i==2
. This can be fixed by a couple of changes to the inner loop:
#include <stdio.h>
int main(void)
{
for (int i=2; i<100; i++)
{
for (int j=2; j<=i; j++) // Changed upper bound
{
if (i == j) // Changed condition and reversed order of if:s
printf("%d\n",i);
else if (i%j == 0)
break;
}
}
}
4
solved Prime numbers between 1 to 100 in C Programming Language