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

C#实验报告上机一

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

C#实验报告上机一

1.分别控制台SDK方式及集成开发IDE方式编写C#程序,显示输出字符串“这是我的第一个C#程序。 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// 1.分别控制台SDK方式及集成开发IDE方式编写C#程序,显示输出字符串“这是我的第一个C#程序。
namespace Suke.day02
{
    internal class Demo1
    {
        static void Main(string[] args)
        {
            Console.WriteLine("这是我的第一个C#程序。");
            Console.ReadKey();
        }
    }
}

 

 

2.分别按int,long,float,double类型定义两个变量并赋初值,并计算同类型变量的和、差、积、商,最后输出相应的运算结果。 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// 2.分别按int,long,float,double类型定义两个变量并赋初值,并计算同类型变量的和、差、积、商,最后输出相应的运算结果。
namespace Suke.day02
{
    internal class Demo2
    {
        static void Main(string[] args)
        {
            int a = 1;
            int b = 2;
            Console.WriteLine("a + b = {0}", a + b);
            Console.WriteLine("a - b = {0}", a - b);
            Console.WriteLine("a * b = {0}", a * b);
            Console.WriteLine("a / b = {0}", a / b);
            Console.WriteLine("a % b = {0}", a % b);
            
            long c = 3;
            long d = 4;
            Console.WriteLine("c + d = {0}", c + d);
            Console.WriteLine("c - d = {0}", c - d);
            Console.WriteLine("c * d = {0}", a * b);
            Console.WriteLine("c / d = {0}", c / d);
            Console.WriteLine("c % d = {0}", c % d);
                
            float f = 5;
            float g = 6;
            Console.WriteLine("f + g = {0}", f + g);
            Console.WriteLine("f - g = {0}", f - g);
            Console.WriteLine("f * g = {0}", f * g);
            Console.WriteLine("f / g = {0}", f / g);  
            Console.WriteLine("f % g = {0}", f % g);
                
            double h = 7;
            double i = 8;
            Console.WriteLine("h + i = {0}", h + i);
            Console.WriteLine("h - i = {0}", h - i);
            Console.WriteLine("h * i = {0}", h * i);
            Console.WriteLine("h / i = {0}", h / i);
            Console.WriteLine("h % i = {0}", h % i);
            Console.ReadKey();
        }
    }
}

 

3.试编程,从键盘任意输入两个整数分别赋值给a和b,并比较两个数的大小,按从小到大的顺序输出两个数。 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//3.试编程,从键盘任意输入两个整数分别赋值给a和b,并比较两个数的大小,按从小到大的顺序输出两个数。
namespace Suke.day02
{
    internal class Demo3
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入两个整数分别赋值给a和b");
            String s1 = Console.ReadLine();
            String s2 = Console.ReadLine();
            int a = int.Parse(s1);
            int b = int.Parse(s2);
            if(a <= b)
            {
                Console.WriteLine("a = {0}", a);
                Console.WriteLine("b = {0}", b);
            }else if(a > b)
            {
                Console.WriteLine("b = {0}", b);
                Console.WriteLine("a = {0}", a);
            }
            Console.ReadKey();
        }
    }
}

 

 

4.试编程,从键盘任意输入一个整数给变量x,计算并输出分段函数y的值: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//4.试编程,从键盘任意输入一个整数给变量x,计算并输出分段函数y的值:
namespace Suke.day02
{
    internal class Demo4
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入一个整数给变量x");
            String s = Console.ReadLine();
            int x = Convert.ToInt32(s);
            float y;
            if (x >= 1)
            {
                y = 2 * x + 1;
                Console.WriteLine(y);
            }else if (x < 1)
            {
                y = (3 * x) / (x - 1);
                Console.WriteLine(y);
            }
            Console.ReadKey();
        }
    }
}

 

 

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

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

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