★☆题目79(无忧id 55 数字运算题)
请编写函数void countValue(int *a,int *n),它的功能是:求出1到1000之内能被7或11整除但不能同时被7或11整除的所有整数放在数组a中,并通过n返回这些数的个数。
部分源程序存在文件prog1.c中。
请勿改动主函数main()和输出数据函数writeDAT()的内容。
#include <conio.h>
#include <stdio.h>
void countValue(int *a,int *n)
{ int i;
*n=0;
for(i=1;i<=1000;i++)
if(i%7==0&&i%11||i%7&&i%11==0)
a[(*n)++]=i;
}
main()
{
int aa[1000],n,k;
clrscr();
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0)printf("\n");
else printf("%5d",aa[k]);
writeDAT();
}
writeDAT()
{
int aa[1000],n,k;
FILE *fp;
fp=fopen("out19.dat","w");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0) fprintf(fp,"\n");
else fprintf(fp,"%5d",aa[k]);
fprintf(fp,"\n");
fclose(fp);
}
下一篇:2006年9月全国等级考试三级c语言上机题库(八十一)
★☆题目81(无忧id 32 整数各位数运算题)查看详情]