C#编程题分享(1)

求四个整数中的最大值和最小值问题

编写⼀个程序,对输⼊的4个整数,求出其中的最⼤值和最⼩值,并显⽰出来。

cs 复制代码
Console.WriteLine("请分别输入四个整数:");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
int d = Convert.ToInt32(Console.ReadLine());
int max = a, min = a;
if (max < b) max = b;
if (max < c) max = c;
if (max < d) max = d;
if (min > b) min = b;
if (min > c) min = c;
if (min > d) min = d;
Console.WriteLine("这四个整数的最大值是:{0},最小值是:{1}", max, min);

3n + 1问题

3n + 1问题:对于任意⼤于1的⾃然数n,若n为奇数,将n变成3n + 1,否则变成n的⼀半。经过若⼲次这样的变化,n⼀定会最终变成1,⽐如,7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40→ 20 → 10 → 5 → 16 → 8 → 4 →2 → 1

cs 复制代码
Console.WriteLine("请输入一个自然数:");
int n = Convert.ToInt32(Console.ReadLine());
int count = 0;
while (n != 1)
{
    if (n % 2 == 1) n = 3 * n + 1;
    else n = n / 2;
    count += 1;
    Console.WriteLine(n);
}
Console.WriteLine("一共经历了{0}次变化", count);

学员增长问题

2023年培养学员80000⼈,每年增⻓25 %,请问按此增⻓速度,到哪⼀年培训学员⼈数将达到20万⼈?

cs 复制代码
int number = 80000;
int year = 2023;
while (number < 200000)
{
    number += (int)((double)number * 0.25);
    year++;
}
Console.WriteLine("到{0}年人数达到20万", year);
相关推荐
kylezhao20191 小时前
C# 文件的输入与输出(I/O)详解
java·算法·c#
座山雕~1 小时前
Springboot
android·spring boot·后端
kylezhao20192 小时前
C# TreeView 控件详解与应用
c#
韩立学长2 小时前
基于Springboot流浪动物救助系统o8g44kwc(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
我命由我123453 小时前
充血模型与贫血模型
java·服务器·后端·学习·架构·java-ee·系统架构
小镇学者3 小时前
【other】Goofy Node
后端
颜淡慕潇4 小时前
动态代理赋能:高效爬取沃尔玛海量商品信息与AI分析实战
人工智能·后端
FL16238631294 小时前
C# winform部署yolo26-obb旋转框检测的onnx模型演示源码+模型+说明
开发语言·c#
半夏知半秋5 小时前
kcp学习-通用的kcp lua绑定
服务器·开发语言·笔记·后端·学习
hero.fei5 小时前
kaptcha 验证码生成工具在springboot中集成
java·spring boot·后端