教你夺冠


私信TA

用户名:835685327

访问量:148344

签 名:

相互交流 相互学习

等  级
排  名 13
经  验 21570
参赛次数 0
文章发表 84
年  龄 0
在职情况 学生
学  校 辣鸡施工大学
专  业

  自我简介:

努力刷题 熟能生巧!

两种方式实现:


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;
}
2023-04-09 14:27:32
#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;
}
2023-03-23 21:31:07
/*
将一个字符串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);
}
2023-03-23 19:35:35
#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;
    
}
为啥我这输出有个问号?
2022-11-05 06:07:13
#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]);
}
2022-05-14 17:15:12
#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;
}
2022-01-19 19:06:56
#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]);
		}
	 }
2022-01-19 17:57:23
#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;
}
2022-01-03 11:51:50