我做了一下:
1。#include <stdio.h>
#include <string.h>
main()
{
int k;
int i,yes,j;
int str[10],a[10]={0};
FILE *fp;
if ((fp=fopen("test1_1.txt","at+"))==NULL)
{
getch();
exit(1);
}
for(i=0;i<10;i++)
fscanf(fp,"%d ",&str[i]);
for (i=0;i<10;i++)
{yes=1;
for (j=2;j<str[i]/2;j++)
if (str[i]%j==0)
{yes=0;break;}
if (yes==1){a[k]=str[i];k++;}
}
for (i=0;a[i]!=0;i++){printf("%d ",a[i]);
fprintf(fp,"%4d",a[i]);}
getch();
}
2。
define N 3
#define M 3
#include <stdio.h>
void fun(int a[M][N],int b[N])
{ int min;
int i,j,k=0;
for (i=0;i<N;i++){
j=0;
min=a[j][i];
for (;j<M;j++)if (min>=a[j][i])min=a[j][i];
b[k]=min;
k++;
}
}
main()
{
int a[M][N],b[N];
int i,j;
FILE *fp;
if((fp=fopen("test2_2.txt","rt"))!=NULL)
{
getch();
exit (1);
}
for (i=0;i<M;i++)
for (j=0;j<N;j++)
fscanf(fp,"%d ",&a[i][j]);
fun(a[M][N],b[N]);
for (j=0;j<N;j++)printf("%3d",b[j]);
}
3。
#include <stdio.h>
int create(int a[],int m)
{
int i=0,j;
for (j=1;j<=m;j++)
if (j%3==0||j%7==0){
*(a+i)=j;
i++;}
}
main()
{ int i;
int m,b[100]={0};
FILE *fp;
if ((fp=fopen("test3_3","w"))==NULL)
{
getch();
exit (1);}
printf("input numbers:");
scanf("%d",&m);
create(b,m);
for (i=0;b[i]!=0;i++){
printf("%4d",b[i]);
fprintf(fp,"%4d",b[i]);
}
getch();
}