I was creating the program for generating prime number between 1 to 100 where I have already stored the first and second element of the array manually and I use the for loop to generate the next odd number and then I divided the number generated with integer 2 which I stored it in variable primeindex e.g.=9/2= 4.5 and the division gets stored in variable a so the value of a is 4.5 for this loop and then I nested another for loop to check the number is prime or not by generating a number from 2 to number stored in variable a and then dividing the odd number generated in the main for loop by the the number generated by second for loop and checking if the reminder is 0 or not for each loop "e.g. 9/2 has reminder 1, 9/3 has reminder 0" and if the reminder is 0 then the odd number generated gets skipped and the next odd number is generated and if the reminder of that number is not 0 then it gets stored in array and the loops goes on until the the program finds all the primenumber till 100 and it prints it out but it not working as its intended like can some one tell me what's the problem here.
#include<stdio.h>
#include<stdlib.h>
int main() {
int primenum[50];
int i, j;
int a;
int primeindex = 2;
primenum[0] = 2;
primenum[1] = 3;
//generating the number
for (i = 5; i <= 100; i = i + 2) {
//checking if the number is nirme number or not
a = i / primeindex;
for (j = 2; j <= a; j = j + 1) {
if (i % j == 0) {
break;
} else
primenum[primeindex] = i;
++primeindex;
}
}
//printing out the array
for (i = 0; i <= 50; i++) {
printf("\n\n%d", primenum[i]);
}
}