两种方式实现:
1) 用scanf输入存放到一个字符数组,然后逆序拷贝到另一个字符数组,然后输出
#include <stdio.h> #include <string.h> int main(void) { char strinput[100]; scanf("%[^\n]", strinput); //除了换行符以外的字符全部接收 char stroutput[100]; int i = 0; int j = 0; int len = strlen(strinput); //逆序拷贝 for (i = len - 1; i >= 0; i--) { stroutput[j++] = strinput[i]; } stroutput[j] = '\0'; printf("%s\n", stroutput); return 0; }
2) 用getchar接收一个个字符存放在数组中,然后逆序putchar输出
#include <stdio.h> #include <string.h> int main(void) { char c; char output[100]; int index = 0; int i = 0; while ((c = getchar()) != EOF && c != '\n' && i <= 100) { output[index++] = c; i++; } //output[index] = '\0'; for (i = index - 1; i >= 0; i--) { putchar(output[i]); } //putchar('\n'); return 0; }
0.0分
135 人评分
#include<stdio.h> #include<string.h> int main() { int i; char str[100]; gets(str); for (i = strlen(str) - 1; i >= 0; i--) { printf("%c", str[i]); } return 0; }
#include<stdio.h> //递归大法好 void convert(char str[100]){ if(*str=='\0')return; else convert(str+1); printf("%c",*str); } int main() { char str[100]; gets(str); convert(str); return 0; }
/* 将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。 */ #include <stdio.h> #include <string.h> main() { char str[100],*p,*q,t; gets(str); p=str; q=str+strlen(str)-1; while(p<q) { t=*p; *p=*q; *q=t; p++; q--; } printf("%s\n",str); }
#include<stdio.h> #include<string.h> #define SIZE 100 int main() { char a[SIZE]; int len; gets(a); for(len=strlen(a)-1;len>=-1;len--) printf("%c",a[len]); return 0; } 为啥我这输出有个问号?
Jeopardize 2022-11-05 15:02:54 |
以及解决
Jeopardize 2022-11-05 15:03:07 |
已经解决
#include<stdio.h> int main() { char a[100],*p; gets(a); int b=0; p=a; while(*p!='\0') { b++; p++; } for(int j=b-1;j>=0;j--) printf("%c",a[j]); }
#include<stdio.h> int main() { char str[100]; scanf("%[^\n]",str); int len =strlen(str); int i; for(i=len-1;i>=0;i--) { printf("%c",str[i]); } return 0; }
#include<stdio.h> #include<string.h> //void test(char*str,int len) //{ // int i; // for(i=len-1;i>=0;i--) // { // printf("%c",str[i]); // } //} int main() { char str[100]; scanf("%s",str); int len =strlen(str); //test(str,len); int i; for(i=len-1;i>=0;i--) { printf("%c",str[i]); } }
1021王俊峰 2022-01-19 18:13:01 |
空格就不行了啊啊啊
#include<stdio.h> void test(char* str,int sz) { int i = 0; for (i = sz - 1; i >= 0; i--) { printf("%c", str[i]); } } int main() { char arr[100]; int count = 0; int sz = sizeof(arr) / sizeof(arr[0]); scanf("%[^\n]", arr); while (arr[count] != '\0') { count++; } test(arr, count); return 0; }
A+B for Input-Output Practice (V) (C语言代码)浏览:442 |
三进制小数 (C语言代码)浏览:1017 |
点我有惊喜!你懂得!浏览:1218 |
破解简单密码 (C语言代码)浏览:1750 |
时间转换 (Java代码)浏览:572 |
C语言训练-排序问题<1> (C语言代码)浏览:598 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:622 |
字符串比较 (C语言代码)答案错误????浏览:595 |
IP判断 (C语言代码)浏览:761 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:536 |