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);
相关推荐
沛沛rh454 小时前
用 Rust 实现用户态调试器:mini-debugger项目原理剖析与工程复盘
开发语言·c++·后端·架构·rust·系统架构
消失的旧时光-19434 小时前
Spring Boot + MyBatis 从 0 到 1 跑通查询接口(含全部踩坑)
spring boot·后端·spring·mybatis
SamDeepThinking5 小时前
Spring AOP记录日志,生产环境的代码长什么样
java·后端·架构
小江的记录本5 小时前
【网络安全】《网络安全三大加密算法结构化知识体系》
java·前端·后端·python·安全·spring·web安全
GetcharZp5 小时前
「干掉 Gin?」极致性能的 Go Web 框架 Fiber:这才是真正的“快”!
后端
希望永不加班5 小时前
SpringBoot 中 AOP 实现多数据源切换
java·数据库·spring boot·后端·spring
2601_949814695 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互
超级无敌攻城狮6 小时前
Agent 到底是怎么跑起来的
前端·后端·架构
二妹的三爷6 小时前
私有化部署DeepSeek并SpringBoot集成使用(附UI界面使用教程-支持语音、图片)
spring boot·后端·ui
神奇小汤圆6 小时前
程序员面试必备的Java八股文,适合所有的Java求职者
后端