编写一个C语言程序?
2020-04-27
#include <stdio.h>
int main() {
int n, c = 0, num = 0;
do {
printf("请输入一个二位数n(80<=n<=99): ");
scanf("%d", &n);
}while (n < 80 || n > 99);
int a[100];
for (int i = 1; i <= n; i++)
a[i] = 1;
while (c < n - 1) {
for (int i = 1; i <= n; i++) {
if (a[i] == 1)
num++;
if (num == 3) {
a[i] = 0;
c++;
num = 0;
}
}
}
for (int i = 1; i <= n; i++)
if (a[i] == 1)
printf("最初是%d号\n", i);
return 0;
}
数学方法
#include <stdio.h>
int main() {
int n, c = 0;
do {
printf("请输入一个二位数n(80<=n<=99): ");
scanf("%d", &n);
}while (n < 0 || n > 99);
for (int i = 2; i <= n; i++)
c = (c + 3) % i;
printf("最初是%d号\n", c + 1);
return 0;
}