C语言数组元素平移算法实现:将数组前p个元素移动到最后
#include <stdio.h>
void fun(int *w, int p, int n) { int i, j, t; for (i = 0; i <= p; i++) { t = w[0]; for (j = 0; j < n - 1; j++) { w[j] = w[j + 1]; } w[n - 1] = t; } }
int main() { int a[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int i, m; scanf("%d", &m); fun(a, m, 12); for (i = 0; i < 12; i++) printf("%3d", a[i]); printf("\n"); return 0; }
原文地址: https://www.cveoy.top/t/topic/ol6Y 著作权归作者所有。请勿转载和采集!