【问题标题】:Fibonacci Series Extension [closed]斐波那契数列扩展[关闭]
【发布时间】:2014-11-09 17:57:30
【问题描述】:

如何在 C# 中编写代码来查找字母的总和

如果 A=0;B=1,C=A+B,D=B+C,E=C+D.....

示例 CD=1+2=3,

我试过这种方式,输入是字符串,输出是字母的总和

using System;

public class Test
{
    public static (int output1)
    public static void Main(string input1)
    {
        // your code goes here
    }
}

【问题讨论】:

  • 我们不是来做你的“家庭作业”
  • @ÁngelDiMaría 添加此答案:D 你让我开心:)
  • 找到答案的最佳方式是Pay Attention in Class
  • 我已经尝试为这个问题编写代码。请帮忙写代码。
  • 我必须在不使用字典列表的情况下解决这个问题

标签: c# sequence fibonacci


【解决方案1】:

不使用字典列表的答案

class Program
    {
        static void Main(string[] args)
        {
            string test = "abcdef";
            int sum = 0;  
            foreach (char c in test)
            {
                int letterNumber = char.ToUpper(c) - 64;  
                sum += rtnDegint(letterNumber);
            }  
            Console.WriteLine(sum);
        }

        int rtnDegint(int n)
        {
            int first = 0, second = 1, next = 0, c;  
            for (c = 0; c < n; c++)
            {
                if (c <= 1)
                    next = c;
                else
                {
                    next = first + second;
                    first = second;
                    second = next;
                }
            }
            return next;
        }
    }

【讨论】:

  • 得到它 static int rtnDegint(int n)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-05
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
相关资源
最近更新 更多