How to write code in C language to output in reverse or…
Here is a simple C program that can reverse and output a user-inputted string.
#include <stdio.h>
#include <string.h>
void reverse(char* str) {
int len = strlen(str);
for (int i = len - 1; i >= 0; i--) {
printf("%c", str[i]);
}
printf("\n");
}
int main() {
char str[100];
printf("请输入一个字符串:");
scanf("%s", str);
printf("逆序输出字符串为:");
reverse(str);
return 0;
}
After running the program, users can input a string and the program will output the string in reverse.