#include <stdio.h> #include <string.h>

void shift_s(char a[], int n, int m);

int main(void) { char stra[80]; int m, n;

printf("Enter a string:");
gets(stra);

n = strlen(stra);

printf("Enter m:");
scanf("%d", &m);

shift_s(stra, n, m);

printf("After rotate right 3 bits:");
puts(stra);

}

void shift_s(char a[], int n, int m) { int i, j; char t;

for (i = 1; i <= m; i++) {
    t = a[n - 1];
    
    for (j = n - 2; j >= 0; j--) {
        a[j + 1] = a[j];
    }
    
    a[0] = t;
}

}

C 语言字符串循环右移代码实现

原文地址: https://www.cveoy.top/t/topic/pkiw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录