Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace C_Sharp空白練習檔
- {
- class Program
- {
- static void Main(string[] args)
- {
- Calculator c = new Calculator();
- int result = c.SumFrom1ToX(5);
- Console.WriteLine(result);
- }
- }
- class Calculator
- {
- public int SumFrom1ToX(int x)
- {
- if(x==1)
- {
- return 1;
- }
- else
- {
- int result = x + SumFrom1ToX(x - 1);
- return result;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment