用数组实现猴子选大王c语言
时间: 2023-11-24 15:50:46 浏览: 146
houzixuandawang,clib语言库函数源码,c语言
以下是用数组实现猴子选大王的C语言代码:
```c
#include <stdio.h>
int main() {
int n, m;
scanf("%d %d", &n, &m);
int a[50];
for (int i = 0; i < n; i++) {
a[i] = i + 1;
}
int count = 0;
int index = 0;
int left = n;
while (left > 1) {
if (a[index] != 0) {
count++;
}
if (count == m) {
a[index] = 0;
count = 0;
left--;
}
index++;
if (index == n) {
index = 0;
}
}
for (int i = 0; i < n; i++) {
if (a[i] != 0) {
printf("%d", a[i]);
}
}
return 0;
}
```
阅读全文