2020-11-30

//有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和;
using System;
namespace Program
{
    
    
    
    public class QiuHe
    {
    
    
        public static void FirstTest()
        {
    
    
            double a = 1;
            double b = 1;
            double fraction = a/b;
            double Sn = 0;
            for(int i=0;i<20;i++{
    
    

                double t1 = a;
                double t2 = b;

                a = t1+t2;

                b = t1;

                fraction = a/b;

                Sn += fraction;

            }
            Console.WriteLine(Sn);
        }

    }
}

 //编写一个应用程序,接受用户输入的一行字符串,判断该字符串是否是回文数?
using System;
namespace Program1
{
    
    
    public class ShuRu
    {
    
    
        public static void Test()
        {
    
    
            string s = "";
            int a = 0;
            Console.WriteLine("请输入一个字符串");
            s = Console.ReadLine();
            char[] b = s.ToCharArray();
            for(int i=0;i<b.Length/2;i++){
    
    
                if(b[i]!=b[s.Length-i-1]){
    
    
                    a = 1;
                }
            }
            if(a==1){
    
    
                Console.WriteLine("该字符串不是回文字符串");
            } else {
    
    
                Console.WriteLine("该字符串是回文字符串");
            }
        }

    }
}

namespace Program2
{
    
    
    class Program
    {
    
    
        static void Main(string[] args)
        {
    
    
            Test2.Test();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_52034378/article/details/110400785
今日推荐