C语言程序100例之C#版-027
C程序源代码:
【程序27】
题目:利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。
1.程序分析:
2.程序源代码:
#include "stdio.h"
#include "conio.h"
main()
{
int i=5;
void palin(int n);
printf("\40:");
palin(i);
printf("\n");
getch();
}
void palin(n)
int n;
{
char next;
if(n<=1)
{
next=getchar();
printf("\n\0:");
putchar(next);
}
else
{
next=getchar();
palin(n-1);
putchar(next);
}
}
![](https://img-my.csdn.net/uploads/201209/02/1346517140_7843.png)
########################
C#语言程序:
using System;
class C327
{
static void Main()
{
int i=5;
Console.Write("\0:");
palin(i);
Console.Write("\n");
}
static void palin(int n)
{
char next;
if(n<=1)
{
next=Convert.ToChar(Console.Read());
Console.Write("\n");
Console.Write(next);
}
else
{
next=Convert.ToChar(Console.Read());
palin(n-1);
Console.Write(next);
}
}
}
![](https://img-my.csdn.net/uploads/201209/02/1346517151_4360.png)