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

.net作业1

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

.net作业1

题目一:在屏幕上输出一个字符串“这是我的第一个C#程序”。要求采用SDK及IDE两种方式实现编程、运行。

 

using System;

namespace zuoye
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("这是我的第一个C#程序");
            Console.ReadKey();
        }
    }
}


using System;

namespace zuoye0
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine("这是我的第一个C#程序");
            System.Console.ReadKey();
        }
    }
}

 题目二:分别定义8种类型的整型变量并赋值,然后在屏幕上输出该变量 

 using System;

namespace zuoye2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = -1;
            byte b = 255;
            short c = -2;
            long d = -3;
            sbyte e = -4;
            uint f = 4294967295;
            ulong h1 = 18446744073709551615;
            ushort i = 65535;
            Console.WriteLine("int a={0},byte b ={1},short c ={2},long d ={3}, sbite e={4},uint f ={5}, ulong h1 ={6},ushort i={7}", a,b,c,d,e,f,h1,i);
            Console.ReadKey();
        }
    }
}

题目三:从键盘上输入两个整数,由用户回答它们的和、差、积、商和取余数运算结果,并统计出正确答案的个数。

using System;

namespace zuoye3
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            Console.WriteLine("请输入一个整数");
            int a = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入一个整数");
            int b = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入两者之和");
            int sum = int.Parse(Console.ReadLine());
            if (sum == a + b)
                count += 1;
            Console.WriteLine("请输入两者之差");
            int sub = int.Parse(Console.ReadLine());
            if (sub == a - b)
                count += 1;
            Console.WriteLine("请输入两者之积");
            int mul = int.Parse(Console.ReadLine());
            if (mul == a * b)
                count += 1;
            Console.WriteLine("请输入两者之商");
            int div = int.Parse(Console.ReadLine());
            if (div == a / b)
                count += 1;
            Console.WriteLine("请输入两者取余");
            int rem = int.Parse(Console.ReadLine());
            if (rem == a % b)
                count += 1;
            Console.WriteLine("您答对了{0}题",count);
            Console.ReadKey();
        }
    }
}

 题目四: 试编程,将从键盘输入的一个矩形的两条边a、b的边长,求矩形的面积及周长。

using System;

namespace zuoye4
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入矩形的长a:");
            double a = double.Parse(Console.ReadLine());
            Console.WriteLine("请输入矩形的宽b:");
            double b = double.Parse(Console.ReadLine());
            double s = a * b;
            double c = 2 * (a + b);
            Console.WriteLine("此矩形面积为{0},周长为{1}",s,c);
            Console.ReadLine();
        }
    }
}

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

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

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