发布网友 发布时间:2022-04-20 06:16
共1个回答
热心网友 时间:2023-09-14 16:21
#include <stdio.h> void main(){ int i,i2,k,k2,n,m,a[20],tmp,tmp2,j=0; scanf("%d %d",&n,&m); for(i=0;i<n;i++) a[i] = i+1; for(i=0;i<n;i++) printf("%d ",a[i]); printf("\r\n"); /********转换开始*****************/ if(n%m==0) { i2 = n/m; k2 = m; } else { i2 = n; k2 = 1; } for(k=0;k<k2;k++) { tmp = a[k]; j = k; for(i=0;i<i2;i++) { j = j+n-m; j = j%n; tmp2 = a[j]; a[j] = tmp; tmp = tmp2; } } /********转换结束*****************/for(i=0;i<n;i++) printf("%d ",a[i]); printf("\r\n");}