通过键盘输入某年某月某日,计算并输出这一天是这一年的第几天。例如,2001年3月5日是这一年的第64天。注意:使用分支结构语句实现。
生活随笔
收集整理的這篇文章主要介紹了
通过键盘输入某年某月某日,计算并输出这一天是这一年的第几天。例如,2001年3月5日是这一年的第64天。注意:使用分支结构语句实现。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System;namespace 日期
{class Program{static void Main(string[] args){Console.WriteLine("請輸入年");int Y = Convert.ToInt32(Console.ReadLine());Console.WriteLine("請輸入月");int M = Convert.ToInt32(Console.ReadLine());Console.WriteLine("請輸入日");int D = Convert.ToInt32(Console.ReadLine());Console.WriteLine(Y + "年" + M + "月" + D + "日是今年的第" + Date(Y,M, D) + "天");}static int Date(int y, int m, int d){//定義b裝天數int b = 0;//數組裝天數int[] array = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//除2月外還有11個月,所以i=1,i<12for (int i = 1; i < m; i++){//閏年if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0){b = b + array[i];}//平年else{array[1] = 28;b = b + array[i];}}d = d + b;//返回天數return d;}}
}
總結
以上是生活随笔為你收集整理的通过键盘输入某年某月某日,计算并输出这一天是这一年的第几天。例如,2001年3月5日是这一年的第64天。注意:使用分支结构语句实现。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 闲云旅游网03(基于vue+elemen
- 下一篇: Prescribed Performan