编写fun,起功能是将所有大于1小于m的非素数存如xx所指的数组中,非素数的个数通过k传回
#include <conio.h>
#include <stdio.h>
void fun( int m, int *k, int xx[] )
{ int i,j=2,z=0;
for(i=3;i<m;i++)
{
{
if(i%j==0)
{xx[z++]=i;j=2;
}
else j++;
}while(j!=2);
}
*k=z;
}
main()
{
int m, n, zz[100];
FILE *out;
clrscr();
printf( "\nPlease enter an integer number between 10 and 100: " );
scanf( "%d", &n );
fun( n, &m, zz );
printf( "\n\nThere are %d non-prime numbers less than %d: ", m, n );
for( n = 0; n < m; n++ )
printf( "\n %4d", zz[n] );
out=fopen ("out.dat", "w");
fun( 27, &m, zz );
fprintf(out, "%d", m);
for( n = 0; n < m; n++ )
fprintf(out, "\n %4d", zz[n]);
fclose (out );
getch();
}