ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C#日常编程练习

2022-01-22 13:02:22  阅读:191  来源: 互联网

标签:Convert 练习 Console C# 编程 System WriteLine using ReadLine


分析:由题意可知指的是11~16岁的才可以进入。

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //只有年龄不大于16的青少年才可以进入
            Console.WriteLine("请输入年龄:");
            int n = Convert.ToInt32(Console.ReadLine());
            bool TF = n >= 11 && n <= 16;
            Console.WriteLine(TF);
        }
    }
}

程序运行结果如下:

 分析:判断奇偶用÷2取余法。

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入一个数,判断奇偶
            Console.WriteLine("请输入数字:");
            int n = Convert.ToInt32(Console.ReadLine());
            bool TF = n%2==0;
            Console.WriteLine(TF);
        }
    }
}

程序运行结果如下:(false代表奇数,true代表偶数)

 

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //年龄18~30,并且为奇数
            Console.WriteLine("请输入年龄:");
            int n = Convert.ToInt32(Console.ReadLine());
            bool TF = n%2!=0 && n>=18 && n<=30;
            Console.WriteLine(TF);
        }
    }
}

程序运行结果如下:

 

 

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //成绩:90~100:A 70~89:B  60~69:C  小于60:D
            Console.WriteLine("请输入成绩:");
            float n = Convert.ToSingle(Console.ReadLine());
            //写条件
            if (n >= 90 && n <= 100)
                Console.WriteLine("该学生成绩为A");
            else if (n >= 70 && n <= 89)
                Console.WriteLine("该学生成绩为B");
            else if (n >= 60 && n <= 69)
                Console.WriteLine("该学生成绩为C");
           else  if (n >= 0 && n <60)
                Console.WriteLine("该学生成绩为D");




        }
    }
}

 程序运行结果如下:

 

 编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入点 平面执教坐标系中 判断象限、原点 还是坐标轴
            Console.WriteLine("请输入点的坐标x:");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.WriteLine("请输入点的坐标y:");
            float y = Convert.ToSingle(Console.ReadLine());
            //写条件
            //在第一象限  x>0 y>0
            if (x>0&&y>0)
                Console.WriteLine("该点在第一象限");
            //在第二象限 x<0 y>0
            else if (x<0&&y>0)
                Console.WriteLine("该点在第二象限");
            //在第三象限 x<0 y<0
            else if (x<0&&y<0)
                Console.WriteLine("该点在第三象限");
            //在第四象限 x>0 y<0
           else  if (x>0&&y<0)
                Console.WriteLine("该点在第四象限"); 
            //在x轴上  y=0
           else  if (y==0)
                Console.WriteLine("该点在x轴上");
            //在y轴上 x=0
           else  if (x==0)
                Console.WriteLine("该点在y轴上");
            //在原点上 x=y=0
            else  if (x==0&&y==0)
                Console.WriteLine("该点在原点上");



        }
    }
}

程序运行结果如下:

 

分析:三角形任意2边之和大于第三边

编写代码如下:(其实也可以简化代码,使用逻辑运算符或者bool来简化代码)

 

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入边长a,b,c  判断是否为三角形
            Console.WriteLine("请输入边长a:");
            float a = Convert.ToSingle(Console.ReadLine());
            Console.WriteLine("请输入边长b:");
            float b = Convert.ToSingle(Console.ReadLine());
            Console.WriteLine("请输入边长c:");
            float c = Convert.ToSingle(Console.ReadLine());
            //判断条件 任意两边之和大于第三边
            if (a + b > c)
            {
                if (a + c > b)
                {
                    if (b + c > a)
                        Console.WriteLine("是三角形");
                    else
                        Console.WriteLine("不是三角形");
                }
                else
                    Console.WriteLine("不是三角形");
            }
            else
                Console.WriteLine("不是三角形");



        }
    }
}

程序运行结果如下:

 

 

 编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入年份 判断是否为闰年 输出Yes 和 No
            Console.WriteLine("请输入年份:");
            int year = Convert.ToInt32(Console.ReadLine());
            if (year % 4 == 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

        }
    }
}

程序运行结果如下:

 

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入非零整数 判断正负 以及输出绝对值
            Console.WriteLine("请输入一个非零整数:");
            int n = Convert.ToInt32(Console.ReadLine());
            if (n == 0)
                Console.WriteLine("该数不是非零整数");
            else if(n>0)
            
                Console.WriteLine("该数是正数,绝对值为{0}", n);
            else if(n<0)
            
                Console.WriteLine("该数是负数,绝对值为{0}", -n);

            

        }
    }
}

程序运行结果如下:

 

 

 

标签:Convert,练习,Console,C#,编程,System,WriteLine,using,ReadLine
来源: https://blog.csdn.net/qq_51196701/article/details/122635294

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有