int joseph(int a[],int n,int m)
{
for(int i = 0;i<n;i++)
a[i] = 1;
int sum = n;
int start = 0;
int count = 0;
while(sum>=2)
{
count = 0;
while(count !=m)
{
if(a[start]!=0)
{
count++;
if(count == m)
break;
}
start = (start + 1)%n;
}
a[start] = 0;
sum--;
cout<<"the content of the array:"<<endl;
for(int t = 0;t<n;t++)
cout<<a[t]<<"\t";
cout<<endl;
}
for(int j = 0;j<n;j++)
if(a[j]!=0)
{
return j+1;
}
}
{
for(int i = 0;i<n;i++)
a[i] = 1;
int sum = n;
int start = 0;
int count = 0;
while(sum>=2)
{
count = 0;
while(count !=m)
{
if(a[start]!=0)
{
count++;
if(count == m)
break;
}
start = (start + 1)%n;
}
a[start] = 0;
sum--;
cout<<"the content of the array:"<<endl;
for(int t = 0;t<n;t++)
cout<<a[t]<<"\t";
cout<<endl;
}
for(int j = 0;j<n;j++)
if(a[j]!=0)
{
return j+1;
}
}