// 请编写函数fun,它的功能是:求出1到100之内能被7或者11整除,但不能同时被7和11整除的所有整数,并将他们放在a所指的数组中,通过n返回这些数的个数。
#include <stdio.h>
int fun(int* a) {
int result[100];
int count = 0;
for (int i = 1; i <= 100; i++) {
if ((i % 7 == 0 || i % 11 == 0) && !(i % 7 == 0 && i % 11 == 0)) {
result[count] = i;
count++;
}
}
for (int j = 0; j < count; j++) {
a[j] = result[j];
}
return count;
}
int main() {
int a[100];
int n = fun(a);
printf("Array of numbers:\n");
for (int i = 0; i < n; i++) {
printf("%d ", a[i]);
}
printf("\n");
printf("Number of elements: %d\n", n);
return 0;
}
标签:11,int,fun,整除,100,求出
From: https://www.cnblogs.com/yesiming/p/18240093