#include
void main()
{
int c;
if((c=getchar())!='\n')
{
main();
printf("%c",c);
}
else printf("\n");
}
这个程序是递归,每次将获取的字符串用变量c存储起来,然后接收下一个字符。直到\n,然后每一层函数输出自己的c,再返回上一层的c
这段程序等价的非递归形式是
#include "stdio.h"
#define MAX 1000
int main()
{
int c[MAX];
int esp = 0;
while ((c[esp++]=getchar())!='\n');
while (esp-- >= 0)
printf("%c",c[esp + 1]);
printf("\n");
}
如果问题得到解决,请点我回答左上角的采纳