第一个:#include <stdio.h>
#include <string.h>
int main()
{
int p;
int N;
int a[3000] = {0};
int i;
int j;
int k = 0;
printf("输入");
scanf("%d%d",&N,&p);
for(i = 0; i < N; i++)
{
a[i] = i+1;
}
printf("输出");
while (N > 0)
{
i = (i + p - 1) % N;
k++;
printf("%d ",a[i]);
for(j = i+1; j < N; j++)
{
a[j-1] = a[j];
}
N--;
}
return 0;
}
第二个#include <stdio.h>
#include <string.h>
int main()
{
int p;
int N;
int a[3000] = {0};
int i;
int j;
int k = 0;
printf("输入");
scanf("%d%d",&N,&p);
printf("输出");
for(i = 0; i < N; i++)
{
a[i] = i+1;
}
while (N > 1)
{
i = (i + p - 1) % N;
k++;
printf("%d ",a[i]);
for(j = i+1; j < N; j++)
{
a[j-1] = a[j];
}
N--;
if(i == N)
{
i = 0;
}
}
printf("\n%d", a[i]);
return 0;
}
再要不然直接把你需要的格式打出来 |