当前位置:网站首页>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;
}
边栏推荐
- Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
- Introduction to random and threadlocalrandom analysis
- Anti clockwise rotation method of event arrangement -- PHP implementation
- Global and Chinese markets of digital PCR and real-time PCR 2022-2028: Research Report on technology, participants, trends, market size and share
- When synchronized encounters this thing, there is a big hole, pay attention!
- Experiment 7. IPv6
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
- 2021 annual summary - it seems that I have done everything except studying hard
猜你喜欢

Introduction to random and threadlocalrandom analysis

Process communication and thread explanation

MPLS experiment

Star leap plan | new projects are continuously being recruited! MSR Asia MSR Redmond joint research program invites you to apply!
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14](/img/c5/dde92f887e8e73d7db869fcddc107f.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14

2021-08-09

Enter the smart Park, and change begins here
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11](/img/6a/398d9cceecdd9d7c9c4613d8b5ca27.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11

How to realize the function of Sub Ledger of applet?

IPv6 experiment
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Iframe to only show a certain part of the page
Single spa, Qiankun, Friday access practice
Reptile learning winter vacation series (2)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Enter the smart Park, and change begins here
[notes] in depth explanation of assets, resources and assetbundles
Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
Detailed explanation of classic process synchronization problems
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
VBA, JSON interpretation, table structure -json string conversion
MPLS experiment
[ES6] template string: `string`, a new symbol in es2015
The database connection code determines whether the account password is correct, but the correct account password always jumps to the failure page with wrong account password
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
What if the chat record is gone? How to restore wechat chat records on Apple Mobile
Mongodb vs mysql, which is more efficient
IPv6 experiment
Introduction of network security research direction of Shanghai Jiaotong University
Interview question MySQL transaction (TCL) isolation (four characteristics)