I have a program that generates prime numbers. This code works fine when i want the first 100 and 200 primes, but puts out a Floating point exception whenever I use a value above 300 for total. The problem seems to be in the array, but I don't understand what is happening.
#include<stdio.h>
int main()
{
int total = 500;
int primes[total];
primes[0] = 2;
int max = 1;
int current = 3;
int index = 0;
printf("%d\n",2);
while(max != total)
{
for(index = 0; index <= max + 1; index++)
{
if(index == max + 1){
primes[index] = current;
printf("%d\n",current);
max = max + 1;
current = current + 1;
break;
} else {
if(current % primes[index] == 0){
current = current + 1;
break;
}
}
}
}
}