Fibonacci级数扩展
本文关键字:扩展 Fibonacci | 更新日期: 2023-09-27 18:22:03
如何在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
}
}
不使用字典列表的答案
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;
}
}