易截截图软件、单文件、免安装、纯绿色、仅160KB

C_在switch

 源码:
# include <stdlib.h>
# include <stdio.h>
 
int main()
{
    int month;
    int day;
     
    printf("please input the month number: ");
    scanf("%d", &month);
    switch (month)
    {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12: day=31; // 有31天的月份情况
             break;
    case 4:
    case 6:
    case 9:
    case 11: day=30; // 有30天的月份的情况
             break;
    case 2:  day=28; // 非闰年的2月有28天
             break;
    default: exit(0);
    }
    printf("1999.%d has %d days.\n", month, day);
    return 0;
}
 
其中,若能按输入年份分为闰年和非闰年输出每月天数,可能更好。(待解决)


相关文档:

C/C++中的日期和时间 time_t与struct tm转换

 摘要:
本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法。
关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch ......

C_数据类型转换

 源码:
# include <stdio.h>
 
int main()
{
    /* 定义变量并赋初值 */
     int    a = 5;       
    char   c = 'a';   // 'a'的ASC码的值为97
    ......

C_判断语句if与else的组合使用

 源码:
# include <stdio.h>
 
int main()
{
    int x, y;
    printf("请输入自变量x:");
    scanf("%d", &x);
 
    if(x < 6)
    {
        ......

C_判断语句if与else的嵌套使用

 源码:
# include <stdio.h>
 
int main()
{
    /* sex代表输血者的性别,weight代表输血者的体重,cubage代表输血量 */
    int sex, weight, cubage;
    printf("请给出输血者的性别(女性为负数)和体重:(用逗号隔开)");
 &nbs ......

C_使用break和continue控制循环语句

 源码:
# include <stdio.h>
 
int main( )
{
    int radius;
    double area;
    for(radius = 1; radius <= 10 ; radius++)
    {
        area = 3.1416 * radius * radius;
   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号