gpt4 book ai didi

c# - 需要添加2个数字的代码

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:33:06 26 4
gpt4 key购买 nike

我将后面的数字作为字符串

我的实际号码是 1234567890123456789

从这里我必须将它分开为 s=12 s1=6789 s3=3456789012345

像我说的那样

我想补充如下

11+3, 2+4, 6+5, 7+6, 8+7, 9+8 这样输出应该如下所示

4613579012345

请帮忙

最佳答案

    public static string CombineNumbers(string number1, string number2)
{
int length = number1.Length > number2.Length ? number1.Length : number2.Length;
string returnValue = string.Empty;

for (int i = 0; i < length; i++)
{
int n1 = i >= number1.Length ? 0 : int.Parse(number1.Substring(i,1));
int n2 = i >= number2.Length ? 0 : int.Parse(number2.Substring(i,1));
int sum = n1 + n2;

returnValue += sum < 10 ? sum : sum - 10;
}
return returnValue;
}

关于c# - 需要添加2个数字的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4043527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com