C#入门实战:数字计算与条件判断

1.用c#语言实现简单的俩个数字相加的功能

通过convert来实现数据类型的转换

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个数字");
            string numb1 = Console.ReadLine();
            Console.WriteLine("请继续输入一个数字");
            string numb2 = Console.ReadLine();
            Console.WriteLine(Convert.ToInt32(numb1)+Convert.ToInt32(numb2));
        }
    }
}

2.编写一个程序,用户输入俩个整数,计算俩个整数的商,并返回结果

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个数字");
            string num1 = Console.ReadLine();
            Console.WriteLine("请继续输入一个数字");
            string num2 = Console.ReadLine();

            int num01 = Convert.ToInt32(num1);
            int num02 = Convert.ToInt32(num2);
            float result = (float)num01/num02;
            Console.WriteLine("商的结果是"+result);
        }
    }
}

3.编写一个程序

领取奖励的条件是:

  • 通过前三个关卡
  • 前三关获取的星星数量要大于或等于6个
  • 第二关是一颗星星或第三关是一颗星星

用户输入

  • 第一关获得的星星:如果没有过关,星星数量为零
  • 第二关获得的星星:如果没有过关,星星数量为零
  • 第三关获得的星星:如果没有过关,星星数量为零
  • 第四关获得的星星:如果没有过关,星星数量为零
  • 第五关获得的星星:如果没有过关,星星数量为零

判断该名玩家是否可以获得奖励,如果不可以请输出False,如果可以请输出True

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入第一关获取的星星的数量");
            string l01 = Console.ReadLine();
            Console.WriteLine("请输入第二关获取的星星的数量");
            string l02 = Console.ReadLine();
            Console.WriteLine("请输入第三关获取的星星的数量");
            string l03 = Console.ReadLine();
            Console.WriteLine("请输入第四关获取的星星的数量");
            string l04 = Console.ReadLine();
            Console.WriteLine("请输入第五关获取的星星的数量");
            string l05 = Console.ReadLine();

            int l01star = int.Parse(l01);
            int l02star = int.Parse(l02);
            int l03star = int.Parse(l03);
            int l04star = int.Parse(l04);
            int l05star = int.Parse(l05);

            bool award = l03star > 0 && l03star + l02star + l01star >= 6 && (l02star == 1 || l03star ==1);
            Console.WriteLine("结果是" + award);



        }
    }
}

4.从控制台输入一个整数,如果这个数字大于10,则输出这个数字的二倍,否则什么都不做

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个整数");
            int num = int.Parse(Console.ReadLine());
            if(num > 10)
            {
                Console.WriteLine(num * 2);
            }
        }
    }
}
相关推荐
无限进步_2 小时前
面试题 02.02. 返回倒数第 k 个节点 - 题解与详细分析
c语言·开发语言·数据结构·git·链表·github·visual studio
MyBFuture3 小时前
C#数组详解:一维二维与交错数组
开发语言·windows·c#·visual studio·vision pro
HAPPY酷4 小时前
构建即自由:一份为创造者设计的 Windows C++ 自动化构建指南
开发语言·c++·ide·windows·python·策略模式·visual studio
有来技术4 小时前
ASP.NET Core 权限管理系统(RBAC)设计与实现|vue3-element-admin .NET 后端
vue.js·后端·c#·asp.net·.net
张人玉6 小时前
C#WinFrom中show和ShowDialog的区别
开发语言·microsoft·c#
m0_748233176 小时前
C#:微软的现代编程利器
开发语言·microsoft·c#
Traced back6 小时前
SQL Server数据自动清理系统最终版(C# WinForms完整源码)
数据库·c#·.net
Light607 小时前
Visual Studio 2026深度体验:AI原生IDE如何重塑开发工作流
性能优化·visual studio·github copilot·智能编程·ai原生ide·2026·fluent ui
人工智能AI技术7 小时前
【C#程序员入门AI】Microsoft Extensions for AI (MEAI):统一LLM调用接口,告别厂商绑定
人工智能·c#
William_cl8 小时前
C# ASP.NET路由系统全解析:传统路由 vs 属性路由,避坑 + 实战一网打尽
开发语言·c#·asp.net