Following code:
Code:
#include <stdio.h>
int izbaciSveProste(int n, int x[], int y[])
{
int i;
int flag=0;
for(i=2; i<n/2; i++)
{
if(n%i ==0)
{
flag =1;
break;
}
}
if(flag==1)
return 0;
else
return 1;
}
int main()
{
int i,j,n,x[100],y[100],dest=0;
printf("Koliko elemenata zelite u polju?\n");
scanf("%d", &n);
printf("Unesite elemente:\n");
for(i=0;i<n;i++)
{
scanf("%d",&x[i]);
}
int len = sizeof(x)/sizeof(x[0]);
for(i=0; i<len; i++)
{
if(izbaciSveProste(n,x[i],y[i]))
{
y[dest++]=x[i];
for(j=i; j<len-1; j++)
{
x[j] = x[j+1];
y[dest++]=x[j];
}
i--;
len--;
}
}
printf("Elementi nakon brisanja su:\n");
for(i=0; i<dest; i++)
printf("%d\n",y[i]);;
printf("\n");
return 0;
}
Purpose of this program should be to delete all prime numbers from array x[] with n elements, remaining elements should be rewritten in array y[] and show count of elements in array y[] in the end.I believe that function is okay and error is in main() specifically in storing y[].