)输出m~n之间能被7或11整除的所有数及其个数。要求:用函数实现是否整除的判断?
1个回答
展开全部
|#include <stdio.h>
int fun(int M, int a[])
{
int n = 0;
int i;
for (i = 1; i < M; ++i)
{
if (i%7==0 ||i%11==0)
{
a[n] = i;
n++;
}
}
return n;
}
int main(void)
{
int n;
int count;
int a[100];
int i;
printf("Input M:");
scanf(" %d", &n);
count = fun(n, a);
printf("%d\n", count);
for (i = 0; i < count; ++i)
{
printf(" %d ", a[i]);
}
return 0;
}
int fun(int M, int a[])
{
int n = 0;
int i;
for (i = 1; i < M; ++i)
{
if (i%7==0 ||i%11==0)
{
a[n] = i;
n++;
}
}
return n;
}
int main(void)
{
int n;
int count;
int a[100];
int i;
printf("Input M:");
scanf(" %d", &n);
count = fun(n, a);
printf("%d\n", count);
for (i = 0; i < count; ++i)
{
printf(" %d ", a[i]);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询