C#基本练习

/*
一数列的规则如下:1、1、2、3、5、8、13、21、34....
求第30位数是多少?
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cx
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 1, y = 1;
            int count = 2;
            while (count<30)
            {
                int z = x + y;
                x = y;
                y = z;
                ++count;
            }
            Console.WriteLine("第30位数值是:{0}", y);
            Console.ReadKey();
        }
    }
}


/*
输入一年份,判断是否为闰年
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cx
{
    class Program
    {
        static void Main(string[] args)
        {
            string b= Console.ReadLine();
            int a= Convert.ToInt32(b);
            if((a%4==0&&a%100!=0)||a%400==0)
            {
                Console.WriteLine("是闰年!");
            }
            else
            {
                Console.WriteLine("不是闰年!");
            }
            
            Console.ReadKey();
        }
    }
}

/*
一青年歌手参加比赛,10位评委打分(正整型数字),计算并输出歌手的平均分(去掉一个最高分和最低分)。
平均分以double性数据类型输出。
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cx
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0, min = 101, max = -1,sum=0,grades;
            double aver;
            while (i <= 9)
            {
                grades = Convert.ToInt32(Console.ReadLine());
                i++;
                sum += grades;
                if (grades > max)
                {
                    max = grades;

                }
                if (grades < min)
                {
                    min = grades;
                }
            }
            aver = (sum - max - min) / 8.0;
            Console.WriteLine("该歌手的平均分数是(去掉最高分与最低分):{0}", aver);
            Console.ReadKey();
        }
    }
}

/*
输入一字符串,判断该字符串,判断该字符串是否为“回文”(即顺读和逆读相同的字符串)。
用字符串的toCharArray()方法,将字符串转换为数组。
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cx
{
    class Program
    {
        static void Main(string[] args)
        {
            string source;
            bool b=true ;
            char[]s=new  char [20];
            source = Console.ReadLine();
            s = source.ToCharArray();
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == s[s.Length - i - 1])
                    b = true;
                else
                    b = false;
            }
            if (b)
            {
                Console.WriteLine("{0}是回文!", source);
            }
            else
            {
                Console.WriteLine("{0}不是回文!", source);
            }
            Console.ReadKey();
        }
    }
}

/*
设计一个程序,输出所有的水仙花数。所谓的水仙花数,是指一个三位整数,其各位数字的立方和等于该数的本身。
例如:153=1*1*1+5*5*5+3*3*3.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cx
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 100; i < 1000; i++)
            {
                //int a = Convert.ToInt32(Console.ReadLine());
                int b = i / 100;
                int c = i % 100 / 10;
                int d = i  % 10;
                if (i == (b * b * b + c * c * c + d * d * d))
                {
                    Console.WriteLine("{0} ", i);
                }
            }
            Console.ReadKey();
        }
    }
}

/*
设计一个程序,输入10个数存入数组中,求最大值、最小值和平均值。
*/

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

namespace cx
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = new int[10];
            int min = 10000, max = -10000, sum = 0;
            double aver;
            for(int i=0;i<=9;i++)
            {
                nums[i] = Convert.ToInt32(Console.ReadLine());
                sum += nums[i];
                if (nums [i] > max)
                    max = nums[i];
                if (nums[i] < min)
                    min = nums[i];
            }
            aver = sum  / 10.0;
            Console.WriteLine("最大值为:{0},最小值为:{1},平均值为:{2}", max , min ,aver );
            Console.ReadKey();
        }
    }
}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值