Two ways to output strings in reverse order

Output string in reverse order

One

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main()
{ char a[100]; scanf("%s", &a); int len ​​= strlen(a);//Get characters String length for (int i = len-1; i >= 0; i–) {//traverse printf from end to front ("%c", a[i]); } return 0; }








two

#include<stdio.h>
#include<string.h>
int main(void)
{ char a[100]; scanf("%s", a);//input string a int len ​​= strlen(a); //Get the string length int temp;//Define the intermediate variable for (int i = 0; i <l / 2; i++) {//Fold in half in the middle, swap both sides temp = a[i]; a[i] = a [l-i-1]; a[l-i-1] = temp; } puts(a); }











Guess you like

Origin blog.csdn.net/qq_43745617/article/details/110494925