当前位置: 首页 > news >正文

C#顺序万年历自写的求余函数与周位移算法

        static int 返回月的天数(int 年, int 月){return (月 == 2 ?(((年 % 4 == 0 && 年 % 100 > 0) || 年 % 400 == 0) ? 29 : 28) :(((月 <= 7 && 月 % 2 > 0) || (月 > 7 && 月 % 2 == 0)) ? 31 : 30));}static int 返回年总天数(int 年, int 标 = 0){//跳过标年之前,包含标年,因标年1月1日是周1。return ((年 -= (标 > 0 ? --标 : 标)) > 0 ? 365 * 年 + ((年 / 4) - (年 / 100) + (年 / 400)) : 0);}static int 求余(int 数, int 模){return (数 - 数 / 模 * 模);}static void 顺序万年历(int 年, int 月){//计算本年之前的总天数+本月的前月累计+本月1号int 天 = 返回年总天数(年 - 1, 1900) + 1, 周 = 月, 填 = 返回月的天数(年, 月 - 1);while (--周 > 0) 天 += 返回月的天数(年, 周);周 = 填 - 求余(求余(天, 7) + 6, 7);Console.WriteLine("一 二 三 四 五 六 天");天 = 0;while (天 < 42){Console.Write((++周).ToString("00 "));if (周 >= 填){周 = 0;//转计算本月天数填填 = 返回月的天数(年, 月); }if (求余(++天, 7) == 0) Console.WriteLine();}}

2020年2月

2020年8月
 

2020年9月

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 农历引用;//工程引用中添加DLL文件namespace 控制台
{class Program{static int 返回月的天数(int 年, int 月){return (月 == 2 ?(((年 % 4 == 0 && 年 % 100 > 0) || 年 % 400 == 0) ? 29 : 28) :(((月 <= 7 && 月 % 2 > 0) || (月 > 7 && 月 % 2 == 0)) ? 31 : 30));}static int 返回年总天数(int 年, int 标 = 0){//跳过标年之前,包含标年,因标年1月1日是周1。return ((年 -= (标 > 0 ? --标 : 标)) > 0 ? 365 * 年 + ((年 / 4) - (年 / 100) + (年 / 400)) : 0);}static int 求余(int 数, int 模){return (数 - 数 / 模 * 模);}static void 顺序万年历(int 年, int 月){//计算本年之前的总天数+本月的前月累计+本月1号int 天 = 返回年总天数(年 - 1, 1900) + 1, 周 = 月, 填 = 返回月的天数(年, 月 - 1), 侬 = 月 - 1;while (--周 > 0) 天 += 返回月的天数(年, 周);周 = 填 - 求余(求余(天, 7) + 6, 7);Console.WriteLine(系统农历.月历加载(年, 月, DateTime.Now.Day));Console.WriteLine("周一浓 周二浓 周三浓 周四浓 周五浓 周六浓 周天浓");天 = 0;while (天 < 42){Console.Write((++周).ToString("00"));Console.Write(系统农历.月历加载(年, 侬, 周).Substring(4, 2) + " ");if (周 >= 填){周 = 0;//转计算本月天数填++侬;填 = 返回月的天数(年, 月); }if (求余(++天, 7) == 0) Console.WriteLine();}}static void Main(string[] args){顺序万年历(DateTime.Now.Year, DateTime.Now.Month);Console.WriteLine(".......按任意键退出");Console.ReadKey();}}
}

        private void 窗体绘图(object sender, PaintEventArgs e){int 天 = 返回年总天数(DateTime.Now.Year - 1, 1900) + 1, 周 = DateTime.Now.Month, 填 = 返回月的天数(DateTime.Now.Year, DateTime.Now.Month - 1), 侬 = DateTime.Now.Month - 1;while (--周 > 0) 天 += 返回月的天数(DateTime.Now.Year, 周);周 = 填 - 求余(求余(天, 7) + 6, 7);string 输出 = 农历引用.系统农历.月历加载(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).Substring(0, 6) + "\n周一浓 周二浓 周三浓 周四浓 周五浓 周六浓 周天浓\n";天 = 0;while (天 < 42){输出 += (++周).ToString("00") + 系统农历.月历加载(DateTime.Now.Year, 侬, 周).Substring(4, 2) + " ";if (周 >= 填){周 = 0;//转计算本月天数填++侬;填 = 返回月的天数(DateTime.Now.Year, DateTime.Now.Month);}if (求余(++天, 7) == 0) 输出 += "\n";}if (Convert.ToUInt16(this.WindowState) == 2) e.Graphics.DrawString(输出, new Font("隶书", 14), new SolidBrush(Color.Blue), new PointF(4.0F, this.Height / 2));}

http://www.lryc.cn/news/432874.html

相关文章:

  • 【Java并发编程一】八千字详解多线程
  • CentOS 8FTP服务器
  • C++ | Leetcode C++题解之第385题迷你语法分析器
  • 【软件设计师真题】第一大题---数据流图设计
  • 系统架构的发展历程之模块化与组件化
  • 基因组学中的深度学习
  • 解决老师询问最高分数问题的编程方案
  • com.baomidou.mybatisplus.annotation.DbType 无法引入
  • 从零开始学习JVM(七)- StringTable字符串常量池
  • 数据库课程设计mysql
  • AI学习指南深度学习篇-带动量的随机梯度下降法的基本原理
  • 点餐小程序实战教程03创建应用
  • 鸿蒙自动化发布测试版本app
  • 力扣9.7
  • GPU 带宽功耗优化
  • Linux Centos 7网络配置
  • 第三天旅游线路规划
  • C++第四十七弹---深入理解异常机制:try, catch, throw全面解析
  • go 和 java 技术选型思考
  • 传统CV算法——边缘算子与图像金字塔算法介绍
  • 图像去噪算法性能比较与分析
  • Vision Transformer(ViT)模型原理及PyTorch逐行实现
  • 828华为云征文 | Flexus X实例CPU、内存及磁盘性能实测与分析
  • FreeRTOS学习笔记(六)队列
  • 【Python篇】PyQt5 超详细教程——由入门到精通(中篇一)
  • LinuxQt下的一些坑之一
  • Statement batch
  • PPP 、PPPoE 浅析和配置示例
  • 【Python机器学习】词向量推理——词向量
  • Python 语法糖:让编程更简单(续二)