WV.46-当年第几天

问题及代码:

/*  
*Copyright (c)2014,烟台大学计算机与控制工程学院  
*All rights reserved.  
*文件名称:days.cpp  
*作    者:单昕昕  
*完成日期:2015年2月6日  
*版 本 号:v1.0  
*  
*问题描述:定义一个函数,其参数为年、月、日的值,返回这一天为该年的

第几天。要求在main函数中输入年 
月日,然后调用这个函数求值,并在main函数中输出结果。 
*程序输出:这一天为该年的第几天。 
*/ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test
{
    class Program
    {
        static int days(int y, int m, int d)
        {
            int sum = 0, n;
            for (n = 1; n < m; ++n)
            {
                if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
                {
                    if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12)
                        sum += 31;
                    else if (n == 2)
                        sum += 29;
                    else
                        sum += 30;
                }
                else
                {
                    if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12)
                        sum += 31;
                    else if (n == 2)
                        sum += 28;
                    else
                        sum += 30;
                }
            }
            sum += d;
            return (sum);
        }
        static void Main()
        {
            int year, month, day;
            Console.Write("输入年份:");
            year = int.Parse(Console.ReadLine());
            Console.Write("输入月份:");
            month = int.Parse(Console.ReadLine());
            Console.Write("输入日期:");
            day = int.Parse(Console.ReadLine());
            Console.WriteLine("这是该年的第{0}天。", days(year, month, day));
            Console.ReadLine();
        }
    }
}


运行结果:



知识点总结:

练习使用days方法。


学习心得:

一般都是用静态static。

知识点总结:

乘法口诀表。



学习心得:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值