写一个递归函数实现1到n的累加
解决方案 »
- VS2005不能鼠标断点的问题!
- wav文件合成的问题
- 如何用c#代码执行.net自带的工具,例如csc.exe和windiff.exe
- dateset判断问题
- 关于object 数组的拆箱
- 简单问题:我的tableadapter为什么不能update???
- XmlNameNodeMap map=node.Attributes;请问XmlNameNodeMap 引用何空间?帮帮我!
- 现在写了一个HttpServer控制台现在要实现到winform里
- 听说用变量=nothing可以隐式调用gc,所以不推荐用??
- 如何在C#应用程序或asp.net的web应用中,向一个映射到本地的网络盘中写入文件?
- C#的一个小问题(有答案就结贴)
- 大家帮忙看看这个HashCode怎么写?
写个控制台的,功能实现,尚待优化:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入N:");
int n=int.Parse(Console.ReadLine()); Console.Write("结果是:{0}",GetResult(n));
Console.ReadLine();
}
public static int GetResult(int n)
{
if (n==1)
return 1;
else
return n+GetResult(n-1);}
} }