栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

C#程序作业----实验二

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#程序作业----实验二

**

2.1 编写控制台程序,定义两个单精度实数x、y,值分别为78.5和85.5,求两个数之和

**

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

namespace TEXT1
{
    class Program
    {
        static void Main(string[] args)
        {
            float X = 78.5f;
            float Y = 85.5f;
            float z;

            z = X + Y;

            Console.WriteLine(z);
            Console.ReadKey();


        }
    }
}

**

2.2编写控制台程序,定义两个整数(两个整数的值从键盘输入),定义一个字符串变量,当这个字符变量分别是“+”、“-”、“*”、“/”时,用switch语句输出这两个数的运算结果。(提示:用到的方法有ReadLine()int.Parse()Convert.ToInt32()等)

**

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

namespace TEXT2
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2;
            string ch;

            Console.WriteLine("请从键盘上输入两个整数:");
            num1 = int.Parse(Console.ReadLine());//从键盘上输入1行字符
            num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请从键盘上输入运算符号:");
            ch = Console.ReadLine();

            switch(ch){
                case "+": Console.WriteLine(num1 + num2); break;
                case "-": Console.WriteLine(num1 - num2); break;
                case "*": Console.WriteLine(num1 * num2); break;
                case "/": Console.WriteLine(num1 / num2); break;
            }
         
            Console.ReadKey();

        }
    }
}

**

完成从键盘接受一个成绩,按照优秀(90-100)、良好(70-89)、及格(60-69)、不及格输出等级等级。

**

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

namespace TEXT3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个分数:");

            float  x = int.Parse(Console.ReadLine());;

            if (x >= 90)
            {
                Console.WriteLine("优秀");
                Console.ReadKey();
            }
            else if (x >= 80)
            {
                Console.WriteLine("良好");
                Console.ReadKey();
            }
            else if (x >= 70)
            {
                Console.WriteLine("中等");
                Console.ReadKey();
            }
            else if (x >= 60)
            {
                Console.WriteLine("及格");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("不及格");
                Console.ReadKey();
            }
            
          

        }
    }
}

**

打印九九乘法表

**

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

namespace TEXT4
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++)
            {
                for (int s = 1; s <= i; s++)
                {
                    Console.Write(s + "*" + i + "=" + i * s + " ");
                    if (i == s)
                    {
                        Console.Write("n");
                    }

                }

            }
            Console.Write("请按任意键退出");
            Console.ReadKey();
        }
    }
}

**

猜是否是闰年

**

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TEXT5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int year;
            year = int.Parse(textBox1.Text);
           if(year%4==0 &&year/100!=0||year%400==0)
            {
                textBox2.Text=string.Format("{0}年是闰年!",year);

            }else{
                 textBox2.Text=string.Format("{0}年不是闰年!",year);
            }


        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/910849.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号