关于c语言的函数问题,紧急,多谢!!

来源:百度知道 编辑:UC知道 时间:2024/05/12 05:14:43
写一函数,使输入的一个字符串按反序存放。在主函数中输入和输出字符串

#include <iostream.h>
#include <string.h>
char *power( char *s)
{
int n=strlen(s);
char t;
for(int i=0,j=n-1;i<j;i++,j--)
{
t=s[i];s[i]=s[j];s[j]=t;
}
return s;
}
int main()
{
cout<<"请输入一个字符串:"<<endl;
char str[100];
cin.getline(str,100);
cout<<"逆序后结果为:"<<endl;
cout<<power(str)<<endl;
return 0;
}

给个递归的
#include<stdio.h>
void fun(int n)
{
int next;
if(n<1)
{
next=getchar();
putchar(next);
}

else
{
next=getchar();
fun(n-1);
putchar(next);
}
}
void main()
{
int n;
printf("请输入所要输入的字符的个数:");
scanf("%d",&n);
fun(n);
//getch();
}

123