田舎エンジニアのBlog

~自宅も会社も田んぼに囲まれてますが何か?~

目次

Blog 利用状況

ニュース

自己紹介

リンク

スポンサー

書庫

日記カテゴリ

2009年10月10日 #

mからnの整数の総和を求める

完全に乗り遅れてるけど気にしないでやってみる。

 

using System;
namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            int m = 1;
            int n = 10;
            Console.WriteLine("{0} to {1} the total is {2}", m, n, AddNumber(1, 10));
            Console.ReadKey();
        }
        static int AddNumber(int x, int y) {
            return (x < y ? x + AddNumber(x + 1, y) : y);
        }
    }
}

 

何か無駄が多いと思うけど今の自分の力じゃこんなもん。

 

posted @ 1:25 | Feedback (0)