Thanks alot for your help.. but perhaps i didnt get my piont around..
this is my entire code ..
if you ran this you will see a line that has prime numbers and zeros as well..
I wont to only copy the nonzero elements of that array into another ..
CODE
#include<stdio.h>
#define PRIMENUM 100000
void PrimeNum(unsigned int a[], unsigned int UserInput); /* Function prototype */
int main(void)
{
unsigned int i, UserInput;
unsigned int j = 0;
unsigned int a[PRIMENUM];
unsigned int b[PRIMENUM];
printf(" Enter a Number:" );
scanf( "%d", &UserInput);
while(getchar()!='\n');
if ( UserInput <=0 )
{
printf(" Invalid input, please type a postive non zero number:" );
scanf( "%d", &UserInput);
while(getchar()!='\n');
}
for (i = 0;i < PRIMENUM; i++)/*filss the array with elements*/
a[i] = 2 + i; /* 2,3,4,.., 100000 */
PrimeNum(a, UserInput);
for ( i = 0; i <= UserInput && i < PRIMENUM; i++)
printf(" %d ", a[i] );
getchar();
getchar();
return 0;
}
/*Function void Prime_Num(int num[]) finds the prime integers */
void PrimeNum(unsigned int a[], unsigned int UserInput)
{
unsigned int i;
unsigned int j;
for(i = 0; i <= UserInput && i < PRIMENUM; i++) /*loops through to find the prime integers for the rest of the array*/
{
if(a[i]!=0)
{
for(j = i + 1; j < PRIMENUM; j++)
{
if(a[j]!= 0)
{
if((a[j] % a[i])== 0) /*check if a[j]*/
a[j] = 0; /*is a multiple of a[i]*/
/*if it is a multiple then strike it out*/
}
}
}
}
/* now i need to copy the nonzero elements of a[] to b[]*/
}