最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
约瑟夫环的C语言数组解决程序
时间:2008-04-26 编辑:简简单单 来源:一聚教程网
编号为1,2,...,n的n个人按顺时针方向坐在圆桌边, 每人持有一密码(正整数),从第s人开始报数, 报到第m人出列, 再从下一人开始报, 直至所有的人都出列为止
下面是用数组的方法编的C语言源程序!仅供参考,欢迎多提宝贵意见!
#include
main()
{
int n,s,password;
int a[100];
int i,j,counter1=1,counter2=0;
printf("please input the value of n:");
scanf("%d",&n);
printf("please input the number of the biginer:");
scanf("%d",&s);
if(s>n)
{
printf("please reinput the number less than %d:",n);
scanf("%d",&s);
}
printf("please input the value of the password:");
scanf("%d",&password);
for(i=0;i
j=s-1;
while(counter2!=n)
{
while(password==1)
{
printf("%4d",a[j]);
counter2++;
if(counter2==n)
return;
if(j
else
j=0;
}
while(password!=1&&counter1!=password)
{
if(j
else
j=0;
while(a[j]==0)
{
if(j
else
j=0;
}
counter1++;
if(counter1==password)
{
printf("%4d",a[j]);
a[j]=0;
if(j
else
&nb
-
上一个: 用栈模拟商店进货系统
-
下一个: 图的深度优先遍历
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10