问题描述
一种代码,对两组5个输入进行通用排序,并按asc顺序生成10个值的单个输出.
d第一组输入将仅是num(包括-ve数字和小数).第二组将仅是字符A-J(不区分大小写).根据斐波那契数为每个字符分配累进值.因此,这里A = 0; B = 1; C = 1; D = 2; E = 3; F = 5; G = 8; H = 13;我= 21,J = 34,不允许使用其他字符.
a code which does generic sorting of two sets of 5 inputs and produce a single output of 10 values in asc order.
d first set of input will be num only (including -ve numbers and decimals). The second set will be characters A-J only (case insensitive). Each of the char is assigned progressive values based on Fibonacci numbers. So here, A = 0; B = 1; C = 1; D = 2; E = 3; F = 5; G =8; H = 13; I = 21 and J = 34 and no other characters are permitted.
推荐答案
using System;
using System.Collections.Generic;
using System.Text;
namespace fibseries
{
class Program
{
static void Main(string[] args)
{
int num;
Console.WriteLine("Please Enter a number:");
num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n");
Console.WriteLine("The first " + num + " number(s) in the fibonacci series are: ");
FibonacciSeries(num);
Console.Read();
}
// Fibonacci Code
public static int FibonacciSeries(int n)
{
int previous = -1;
int next = 1;
for (int i = 0; i < n; i++)
{
int sum = next + previous;
previous = next;
next = sum;
Console.WriteLine(next);
}
return next;
}
}
更多示例:
如何在c#中生成斐波那契数列 [ ^ ]
C#斐波那契序列 [ ^ ]
带有一些图像的详细说明:
在C#中使用递归的Fibonacci系列程序 [ ^ ]
More examples:
How to generate Fibonacci series in c#[^]
C# Fibonacci Sequence[^]
Detailed description with some images:
Fibonacci Series Program using Recursion in C#[^]
这篇关于以下程序的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!