继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

今天是相恋4周年纪念日,一个计算我和我老婆相恋时间的程序。

慕粉4019594
关注TA
已关注
手记 1
粉丝 2
获赞 70

// ConsoleApplication6.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

#include <stdio.h>
int main()
{
    /* 定义需要计算的日期 */
    int year = 2016;
    int month = 9;
    int day = 30;   
    int today = 0;
    int i = month - 1;//前面有i个月
    switch (i)
    {
    case 0: today = 0;
        break;
    case 1: today += 31;
        break;
    case 2:

        today += (28 + 31);
        break;
    case 3:
        today += (31 + 28 + 31);
        break;
    case 4:
        today += (31 + 28 + 31 + 30);
        break;
    case 5:
        today += (31 + 28 + 31 + 30 + 31);
        break;
    case 6:
        today += (31 + 28 + 31 + 30 + 31 + 30);
        break;
    case 7:
        today += (31 + 28 + 31 + 30 + 31 + 30 + 31);
        break;
    case 8:
        today += (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31);
        break;
    case 9:
        today += (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30);
        break;
    case 10:
        today += (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31);
        break;
    case 11:
        today += (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30);
        break;
    default:printf("error\n");
    }
    today = day + today;
    int k= 365 - today;
    int w = today + 365 * (year - 2013)+92;
    if( year % 4 == 0 && year % 100 != 0year%400==0)today=today+1;
    else today=today+0;
    printf("%d年%d月%d日是该年的第%d天,距离今年结束还有%d天,是我们相恋第%d天。\n", year, month, day, today,k,w);
    return 0;
}

一个计算我和我老婆相恋时间的程序。
打开App,阅读手记
50人推荐
发表评论
随时随地看视频慕课网APP

热门评论

冰冷的代码与狗粮在我脸上胡乱拍打着

猝不及防吃口狗粮,,,,,请爱护小动物

用swich不如用数组

查看全部评论