源程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp4
{class Program{static void Main(string[] args){int[] a = new int[10];int sum = 10;//共有10个人;int count = 0;//记录退出的人数;int i = 0, j = 0;for (int m = 0; m < sum; m++)a[m] = 1; //数组元素全部初始化为1;while (count < sum - 1){if (a[i] != 0)j++;if (j == 3){a[i] = 0;count++;j = 0;//重新开始,找下一个值!}i++;if (i == sum)i = 0;//实现环(即围成一圈);}for (int m = 0; m < sum; m++)if (a[m] != 0)Console.Write("最后留下的编号是:"+(m + 1) + "n");}}
}
感谢网友
原文链接
.html
本文发布于:2024-02-04 15:39:07,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170710741256766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |