int main()
{
int n1,n2,s=0,cnt,i,k;
printf("\n enter how many persons\n");
scanf("%d",&n1);
int a[n1];
k=n1;
for(i=0;i<n1;i++)
a[i]=i+1;
printf("\n enter every which\n");
scanf("%d",&n2);
while(k>1)
{
cnt=0;
while(cnt<n2)
{
if(a[s]!=0)
cnt+=1;
if(cnt!=n2)
s+=1;
if(s==n1)
s=0;
}
a[s]=0;
k=k-1;
}
for(i=0;i<n1;i++)
{
if(a[i]!=0)
printf("\n The %dth person is saved",i+1);
}
getch();
}
Responses
0 Respones to "josephus problem solver for generalized n"
Post a Comment