又有问题了,麻烦大家~
1.编写程序,根据所输入的年份和月份,计算该月有多少天(题目需要考虑闰年和平年的情况)2.编写程序,袋中有红、黄、绿、蓝色的球共17个,其中这4个色球的个数分别为2、5、3、7个,现从袋中随意拿出一个球,求娶到各种颜色球的概率
#include "stdafx.h" bool IsLeapYear(unsigned int year) { if( (year % 4 == 0) && (year % 100 != 0) || (year % 400 ==0) ) return true; return false; } unsigned int GetDaysByMonth(unsigned int year,unsigned int month) { if (month < 8 && month > 0) { if( month == 2) if( IsLeapYear(year) ) return 29; else return 28; return ( month % 2 + 30); } else if(month > 7 && month <= 12) return ( (month - 1) % 2 + 30 ); return -1; } int main() { unsigned int year,month; printf("please input the year and month:(example: 2010,5)\n"); fflush(stdin); scanf("%d,%d",&year,&month); printf("the days of month %d in the year %d is %d\n",month,year,GetDaysByMonth(year,month)); return 0; }