通过C#编程实现递归算法的完整源代码「建议收藏」

通过C#编程实现递归算法的完整源代码「建议收藏」基于视频讲解的通过C#编程实现递归算法源代码,复制可用无需更改,理解递归算法:using System;using System.Collect

大家好,欢迎来到IT知识分享网。

基于视频讲解的通过C#编程实现递归算法源代码,复制可用无需更改,理解递归算法:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        private string str = null;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int a;
            if(int.TryParse(textBox1.Text,out a))
            {
                textBox2.Text = GetArithmetic(a).ToString();                
                textBox3.Text = str;               
            }
            else
            {
                MessageBox.Show("请输入正确的数字");
            }
        }
        int GetArithmetic(int i)
        {
            str = str + i + ",";
            if (i<=0)
            {
                return 0;
            }
            else if(i==1||i==2)
            {
                return 1;
            }
            else
            {
                return GetArithmetic(i - 2) + GetArithmetic(i - 1);
            }
        }
    }
}

IT知识分享网

结语:喜欢的请关注,点赞、收藏和转发!

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/6771.html

(0)
上一篇 2022-12-20 17:50
下一篇 2022-12-20 18:10

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信