1-1* 顺序表的应用举例2——数组循环左移

版权声明: https://blog.csdn.net/DocManZLR/article/details/86476928
#include <stdio.h>
int main()
{
    int m, n, i, j;
    int a[101];
    scanf("%d %d", &n, &m);
    for(i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    m = m % n;
    for(i = 0; i < m; ++i)
    {
        int temp;
        temp = a[0];
        for(j = 0; j < n - 1; j++)
            a[j] = a[j+1];
        a[n - 1] = temp;
    }
    for(i = 0; i < n; ++i)
    {
        if(i)
            printf(" ");
        printf("%d", a[i]);
    }
}

猜你喜欢

转载自blog.csdn.net/DocManZLR/article/details/86476928
1-1
今日推荐