level 7
___微xue
楼主
题目:
请编写函数void countValue(int *a,int *n),它的功能是:求出1到1000之内能被7或11整除但不能同时被7和11整除的所有整数,其结果按从小到大的顺序存放在数组a中,并通过n返回这些数的个数。
注意:部分源程序存放在PROG1.C中。请勿改动主函数main()和写函数writeDAT()的内容。
【试题程序】
#include <stdlib.h>
#include <stdio.h>
void writeDAT();
void countValue(int *a,int *n)
{
}
void main()
{
int aa[1000],n,k;
system("CLS");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1) %10 ==0)
{
printf("%5d",aa[k]);
printf("
}
else
printf("%5d",aa[k]);
writeDAT();
}
void writeDAT()
{
int aa[1000],n,k;
FILE *fp;
fp=fopen("OUT.DAT","w");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0)
{
fprintf(fp,"%5d",aa[k]);
fprintf(fp,"
}
else
fprintf(fp,"%5d",aa[k]);
fclose(fp);
}
2013年03月17日 15点03分
1
请编写函数void countValue(int *a,int *n),它的功能是:求出1到1000之内能被7或11整除但不能同时被7和11整除的所有整数,其结果按从小到大的顺序存放在数组a中,并通过n返回这些数的个数。
注意:部分源程序存放在PROG1.C中。请勿改动主函数main()和写函数writeDAT()的内容。
【试题程序】
#include <stdlib.h>
#include <stdio.h>
void writeDAT();
void countValue(int *a,int *n)
{
}
void main()
{
int aa[1000],n,k;
system("CLS");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1) %10 ==0)
{
printf("%5d",aa[k]);
printf("
}
else
printf("%5d",aa[k]);
writeDAT();
}
void writeDAT()
{
int aa[1000],n,k;
FILE *fp;
fp=fopen("OUT.DAT","w");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0)
{
fprintf(fp,"%5d",aa[k]);
fprintf(fp,"
}
else
fprintf(fp,"%5d",aa[k]);
fclose(fp);
}

