第八周项目6—本月有几天?

来源:互联网 发布:浪迹网络课程 编辑:程序博客网 时间:2024/05/29 04:05
问题及代码:
/* *Copyright(c)2014,烟台大学计算机学院 *All rights reserved. *文件名称:test.cpp *作者:刘佳琦 *完成日期:2014年10月16日 *版本号:v1.0 * *问题描述:输入年份和月份,输出本月有多少天。 *输入描述:年份以及月份 *程序输出:本月有多少天 */#include <iostream>using namespace std;int main( ){    int x,n,t;    cout<<"输入年份及月份:";    cin >>n>>x;    if (x==2)        if(n%4==0&&n%100!=0||n%400==0)            t=29;        else            t=28;    else if(x==1|x==3|x==5|x==7|x==8|x==10|x==12)        t=31;    else t=30;    cout<<"本月"<<t<<"天";    return 0;}


运行结果:

知识点总结:

if~else的简单运用

心得体会:

这次做的很顺利!比前几次熟练很多了,希望下次能更好!

 

0 0
原创粉丝点击