功能:计算出k以内最大的10个能被13或17整除的自然
功能:计算出k以内最大的10个能被13或17整除的自然数之和。(k<3000)
#include<stdio.h>
#include<conio.h>
int fun(int k)
{
int a=0,b=0;
while(_____1_____)
{
if(_____2_____)
{
_____3_____
_____4_____
}
_____5_____
}
_____6_____
}
void main()
{
int m;
void TestFunc();
printf("Enter m: ");
scanf("%d",&m);
printf("\nThe result is %d\n",fun(m));
TestFunc();
}
void TestFunc()
{
FILE *IN,*OUT;
int s;
int t;
int o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read File Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write File Error");
}
for(s=1;s<=5;s++)
{
fscanf(IN,"%d",&t);
o=fun(t);
fprintf(OUT,"%d\n",o);
}
fclose(IN);
fclose(OUT);
}答案
第1空:(k>=2)&&(b<10)
第2空:(k%13==0)||(k%17==0)
第3空:a=a+k;
第4空:b++;
第5空:k--;
第6空:return a;