用递归求阶层和字符串反转(c#)
2009-07-09 18:11
260 查看
using System;
class Program
{
static void Main(string[] args)
{
int intResult;
string strResult;
intResult=DoFactorial (10);
Console.WriteLine ("10的阶乘是:"+intResult);
strResult=DoStrRev ("This is a test string.");
Console.WriteLine ("字符串反转后为:"+"/n"+strResult);
}
static int DoFactorial(int pF)
{
int result=0;
if(pF==1)
return 1;
result=DoFactorial(pF-1)*pF;
return result;
}
static string DoStrRev(string strTest)
{
if(strTest.Length==1)
return strTest;
string strResult=strTest.Substring (strTest.Length-1,1);
strResult+=DoStrRev(strTest.Substring (0,strTest.Length-1));
return strResult;
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chinarenkai/archive/2008/08/23/2817066.aspx
class Program
{
static void Main(string[] args)
{
int intResult;
string strResult;
intResult=DoFactorial (10);
Console.WriteLine ("10的阶乘是:"+intResult);
strResult=DoStrRev ("This is a test string.");
Console.WriteLine ("字符串反转后为:"+"/n"+strResult);
}
static int DoFactorial(int pF)
{
int result=0;
if(pF==1)
return 1;
result=DoFactorial(pF-1)*pF;
return result;
}
static string DoStrRev(string strTest)
{
if(strTest.Length==1)
return strTest;
string strResult=strTest.Substring (strTest.Length-1,1);
strResult+=DoStrRev(strTest.Substring (0,strTest.Length-1));
return strResult;
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chinarenkai/archive/2008/08/23/2817066.aspx
相关文章推荐
- 递归实现字符串字符反转
- C# 字符串反转,数据排序
- 使用递归实现字符串的反转
- 关于递归实现字符串反转,没想到字符随机写入操作,不new就不行?
- 用递归思想实现字符串反转
- [算法] C# Revert 单词反转字符串[低时间复杂度]
- 一个JavaScript递归实现反转数组字符串的实例
- 每天一个JavaScript实例-递归实现反转数组字符串
- 各种字符串反转方法(异或交换法,递归方法,二分思想)
- C#中实现字符串反转
- (C#)字符串反转
- 小小c#算法题 - 3 - 字符串语句反转
- C#反转字符串的两种方法
- C#上机 第九周 任务2 实现字符串反转
- 由字符串反转(使用递归)引申出来一道Java面试题
- c# 字符串的反转
- C#字符串的反转问题
- C#编程实践--字符串反转
- C# 字符串转意和反转意
- 黑马程序员之C#编程基础学习笔记:将一个字符串数组的元素的顺序进行反转。