当前位置:网站首页>C语言:围圈报号排序问题
C语言:围圈报号排序问题
2022-07-04 12:33:00 【念迟鱼学编程】
问题:
由n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡是到3的人退出圈子,问最后留下的原来第几号的那位。
代码
#include <stdio.h>
int main()
{
int num[50],n,*p,j,loop,i,m,k;
printf("请输入这一圈人的数量:");
scanf("%d",&n);
p = num;
for(j = 0 ; j < n ; j++){
*(p+j) = j+1;
}
i = 0;
m = 0;
k = 0;
while(m<n-1){
if(*(p+i)!=0){
k++;
}
if(k==3){
k = 0;
*(p+i)=0;
m++;
}
i++;
if(i==n){
i = 0;
}
}
printf("现在剩下的人是:");
for(loop=0;loop<n;loop++){
if(num[loop]!=0){
printf("%2d号\n",num[loop]);
}
}
return 0;
}
边栏推荐
- MPLS experiment
- Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
- Haproxy cluster
- Global and Chinese markets for soluble suture 2022-2028: Research Report on technology, participants, trends, market size and share
- Wechat video Number launches "creator traffic package"
- Article download address
- Ternsort model integration summary
- [the way of programmer training] - 2 Perfect number calculation
- Process communication and thread explanation
- When synchronized encounters this thing, there is a big hole, pay attention!
猜你喜欢
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Exness: positive I win, negative you lose
When synchronized encounters this thing, there is a big hole, pay attention!
Complementary knowledge of auto encoder
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
Entitas learning [iv] other common knowledge points
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
2020 Summary - Magic year, magic me
Realize cross tenant Vnet connection through azure virtual Wan
随机推荐
French Data Protection Agency: using Google Analytics or violating gdpr
How do std:: function and function pointer assign values to each other
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
Introduction to random and threadlocalrandom analysis
Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
Global and Chinese market of dental elevators 2022-2028: Research Report on technology, participants, trends, market size and share
Btrace tells you how to debug online without restarting the JVM
Realize cross tenant Vnet connection through azure virtual Wan
Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
asp. Core is compatible with both JWT authentication and cookies authentication
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
Recommend a cool geospatial data visualization tool with low code
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Openssl3.0 learning 20 provider KDF
Games101 Lesson 8 shading 2 Notes
22 API design practices
Reptile learning 3 (winter vacation learning)
Here, the DDS tutorial you want | first experience of fastdds - source code compilation & Installation & Testing