感觉这道题有点蠢,只要硬磕就可以做出来。。。。但是没有用指针,看到网上的都比较复杂我就给个我的简单做法;
1 #include<stdio.h> 2 3 int vis[100]; 4 5 int main() 6 { 7 int n,m,i,k,count=0; 8 scanf("%d%d",&n,&m); 9 k=n; 10 for(i=0;i<n;i++) 11 vis[i]=1; 12 i=0; 13 while(k!=1) 14 { 15 if(i>=n) 16 i=i-n; 17 count=0; 18 while(count!=m) 19 { 20 if(i>=n) 21 i=i-n; 22 if(vis[i]==1) 23 { 24 count++; 25 } 26 i++; 27 } 28 i=i-1; 29 vis[i]=0; 30 k--; 31 32 } 33 for(int i=0;i<n;i++) 34 if(vis[i]==1) 35 printf("%d ",i+1); 36 return 0; 37 38 }