当前位置:网站首页>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;
}
边栏推荐
- It's hard to hear C language? Why don't you take a look at this (V) pointer
- Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- Entitas learning [iv] other common knowledge points
- Googgle guava ImmutableCollections
- 2021-08-09
- MySQL performance optimization index
- Method of setting default items in C # ComboBox control code
- Detailed explanation of NPM installation and caching mechanism
- The most robust financial products in 2022
- 2018 meisai modeling summary +latex standard meisai template sharing
猜你喜欢

Detailed explanation of classic process synchronization problems

22 API design practices
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5](/img/68/4f92ca7cbdb90a919711b86d401302.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5

Wechat video Number launches "creator traffic package"

【数据聚类】第四章第一节3:DBSCAN性能分析、优缺点和参数选择方法

Servlet learning notes

IPv6 experiment

Hongke case study on storm impact in coastal areas of North Carolina using lidar

MySQL advanced review

nn. Exploration and experiment of batchnorm2d principle
随机推荐
JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
World document to picture
Review of week 278 of leetcode II
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
Entitas learning [3] multi context system
Exness: positive I win, negative you lose
Netgear switch basic configuration command set
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
How to judge the advantages and disadvantages of low code products in the market?
Map container
How to realize the function of Sub Ledger of applet?
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
How do std:: function and function pointer assign values to each other
Enter the smart Park, and change begins here
Azure solution: how can third-party tools call azure blob storage to store data?
C语言:求字符串的长度
SAP ui5 date type sap ui. model. type. Analysis of the display format of date
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
Entity framework calls Max on null on records - Entity Framework calling Max on null on records