just stop working when compile...
this code is about prime numbers ... and compile print prime numbers but then shows message stop working.. i used dynamic memory allocation but cant find where is problem... thanks in advance...
Code:
#include<stdio.h>
#include<stdlib.h>
int main() {
int *p=NULL,N,v,b,i=0;
printf("Enter number of elements array:");
scanf("%d",&N);
p=(int *)malloc(N*sizeof(int));
if(p==NULL) {
printf("Out of memory");
exit(1);
}
while(i<=N) {
*(p+i)=0;
i++;
}
for(b=2;b<=N;b++) {
v=b;
if(*(p+v)==0) {
printf("%d ", b);
for (i=2;v<=N;i++) {
v=b*i; /* 2 3 4 5 6 7 8 9 10 11 ... n */
*(p+v)=1; }
}
}
free(p);
printf("\n\nEnd"); /* i put this here just to see if compiler will go to this point,compile will not print this,he just shows message "stop working" before he go to this line */
getch();
return 0;
}