C#上机实验一

1、一数列的规则如下:1、1、2、3、5、8、13、21、34…………,求第30位数是多少?

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 1, y = 1;
            for (int i = 0; i <=28; i++)
            {
                int z = x + y;
                x = y;
                y = z;
            }
            Console.WriteLine(z);
            Console.ReadKey();

        }
    }
}

2、输入一年份,判断是否闰年(被4整除,且不被100整除,或者被400整除)?

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string year=Console.ReadLine();
            int y = int.Parse(year);
            if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
            {
                Console.WriteLine(y+"是闰年");
            }
            else
            {
                Console.WriteLine(y+"不是闰年");

            }
            Console.ReadKey();
        }
    }
}


3、一青年歌手参加比赛,有10位评委打分(分数只能为正整型数字),计算并输出歌手的平均分(去掉一个最高分和一个最低分)。平均分以double数据类型输出。

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            int sum = 0;
            int max = -10, min = 1000;
            for (int i = 0; i < 10; i++)
            {
                int b=int.Parse(a[i]);
                if (max < b)
                    max = b;
                if (min > b)
                    min = b;
                sum += b;
            }
            double aver;
            aver = (sum - max - min) / 8.0;
            Console.WriteLine(aver);
            Console.ReadKey();
        }
    }
}



4、输入一字符串,判断该字符串是否为“回文”(即顺读和逆读相同的字符串)。

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char[] c = s.ToCharArray();
            bool f=true;
            for (int i = 0, j = c.Length-1; i < c.Length; i++, j--)
            {
                if (i == j || j < i)
                    break;
                if (c[i] != c[j])
                {
                    f = false;
                    break;
                }
            }
            if (f)
                Console.WriteLine(s + "是回文字符串");
            else
                Console.WriteLine(s + "不是回文字符串");
            Console.ReadKey();
        }
    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值