当前位置:网站首页>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;
}
边栏推荐
- DVC use case (VI): Data Registry
- Iframe to only show a certain part of the page
- How to judge the advantages and disadvantages of low code products in the market?
- The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
- Some summaries of the 21st postgraduate entrance examination 823 of network security major of Shanghai Jiaotong University and ideas on how to prepare for the 22nd postgraduate entrance examination pr
- Wechat video Number launches "creator traffic package"
- Process communication and thread explanation
- Global and Chinese markets for soluble suture 2022-2028: Research Report on technology, participants, trends, market size and share
- Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
- mm_ Cognition of struct structure
猜你喜欢
Enter the smart Park, and change begins here
When synchronized encounters this thing, there is a big hole, pay attention!
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
French Data Protection Agency: using Google Analytics or violating gdpr
(2021-08-20) web crawler learning 2
Decrypt the advantages of low code and unlock efficient application development
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
Realize cross tenant Vnet connection through azure virtual Wan
Hongke case study on storm impact in coastal areas of North Carolina using lidar
随机推荐
Anti clockwise rotation method of event arrangement -- PHP implementation
Experiment 7. IPv6
How to use "bottom logic" to see the cards in the world?
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
priority_ queue
Workplace liquor bureau must pay attention to
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
Detailed explanation of NPM installation and caching mechanism
Introduction to random and threadlocalrandom analysis
DVC use case (VI): Data Registry
Error: Failed to download metadata for repo ‘AppStream‘: Cannot download repomd. XML solution
Global and Chinese market of dental elevators 2022-2028: Research Report on technology, participants, trends, market size and share
The most robust financial products in 2022
Ml and NLP are still developing rapidly in 2021. Deepmind scientists recently summarized 15 bright research directions in the past year. Come and see which direction is suitable for your new pit
The detailed installation process of Ninja security penetration system (Ninjitsu OS V3). Both old and new VM versions can be installed through personal testing, with download sources
2021-08-09
SAP ui5 date type sap ui. model. type. Analysis of the display format of date
What if the chat record is gone? How to restore wechat chat records on Apple Mobile
Review of week 278 of leetcode II
MySQL advanced (Advanced) SQL statement