热门

最新

红包

立Flag

投票

同城

我的

发布
qq_46647888
qq_46647888
5 年前
trueqq_46647888

1、判断一个数是否是水仙花数
Console.WriteLine("请输入一个数字");
int num = int.Parse(Console.ReadLine());
int a = num % 10;//个位
int b = num % 100 / 10;//十位
int c = num / 100;//百位
int sum = a * a * a + b * b * b + c * c * c;
if (sum == num)
{
Console.WriteLine("{0}是水仙花数",num);
}
else
{
Console.WriteLine("{0}不是水仙花数", num);
}
2、判断一个年份的某个月又多少天
Console.WriteLine("请输入一个年份");
int year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入一个年份");
int mother = Convert.ToInt32(Console.ReadLine());
switch (mother)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Console.WriteLine("31天");
break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
Console.WriteLine("29天");
break;
}
else
{
Console.WriteLine("28天");
break;
}
case 4:
case 6:
case 9:
case 11:
Console.WriteLine("30天");
break;
default:
Console.WriteLine("错误的月份");
break;
}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
SwiftUI Button精品组件之完美的SwiftUI抖动按钮效果(教程含源码) https://www.openswiftui.com/?p=1041
立即登录