| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1944 人关注过本帖
标题:请教一下,这个关于switch的语句~
只看楼主 加入收藏
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
结帖率:50%
收藏
已结贴  问题点数:5 回复次数:7 
请教一下,这个关于switch的语句~
要求输入年份和月份 得出本月天数
#include<stdio.h>
void main()
{
    int year,month;
    printf("input year and month:");
    scanf("%d%d",&year,&month);
     if(month==2)
     {
         if((year%4==0&&year%100!==0)||(year%400==0))
             printf("the days of %d of %d is 29",year,month");
         else printf("the days of %d of %d is 28",year,month");
     }
 switch(month)
     {
         case 1:
         case 3:
         case 5:
         case 7:
         case 8:
         case 10:
         case 12:prtinf("the days of %d of %d is 31",year,month);break;
         case 4:
         case 6:
         case 8:
         case 11:prtinf("the days of %d of %d is 30",year,month);break;
         default:printf("error input!\n");
     }
}
10 errors,1 warning      
不太清楚错在哪里了 请指教qaq
搜索更多相关主题的帖子: switch year printf the case 
2018-04-15 16:35
ab1412
Rank: 7Rank: 7Rank: 7
来 自:M78星球
等 级:黑侠
威 望:4
帖 子:103
专家分:537
注 册:2018-3-15
收藏
得分:5 
程序代码:
#include<stdio.h>

 void main()

 {
     int year,month;
     printf("input year and month:");
     scanf("%d%d",&year,&month);
      if(month==2)
      {
          if((year%4==0&&year%100!=0)||(year%400==0))
              printf("the days of %d of %d is 29",year,month);
          else printf("the days of %d of %d is 28",year,month);
      }
  switch(month)
      {
          case 1:
          case 3:
          case 5:
          case 7:
          case 8:
          case 10:
          case 12:printf("the days of %d of %d is 31",year,month);break;
          case 4:
          case 6:
          case 9:
          case 11:printf("the days of %d of %d is 30",year,month);break;
          default:printf("error input!\n");
  }

 }



错的地方有点多,我就不一一说了,帮你改好了自己看吧

printf("萌新一枚,请多指教");
2018-04-15 16:57
a451410
Rank: 2
等 级:论坛游民
帖 子:34
专家分:48
注 册:2018-3-4
收藏
得分:0 
printf不是prtinf  基本的输出函数要记清楚!  !=(不等于要这样写),不能写成!==   
基本的单词要记住。
2018-04-15 17:05
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
收藏
得分:0 
回复 2楼 ab1412
谢谢您哈~
2018-04-15 17:48
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
收藏
得分:0 
回复 3楼 a451410
一时疏忽。。Thanks♪(・ω・)ノ蟹蟹~
2018-04-15 17:49
欧讷河文
Rank: 2
等 级:论坛游民
帖 子:15
专家分:12
注 册:2018-3-28
收藏
得分:0 
回复 2楼 ab1412
你这个输2月份有问题的  不是天数问题 是后面跟着error input!
2018-04-16 18:24
孤傲晴天
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-4-9
收藏
得分:0 
最终版:

#include<stdio.h>
 void main()
 {
     int year,month;
     printf("input year and month:");
     scanf("%d%d",&year,&month);
      if(month==2)
      {
          if((year%4==0&&year%100!=0)||(year%400==0))
              printf("the days of %d of %d is 29",year,month);
          else printf("the days of %d of %d is 28",year,month);
      }
    else
    {
      switch(month)
          {
              case 1:
              case 3:
              case 5:
              case 7:
              case 8:
              case 10:
              case 12:printf("the days of %d of %d is 31",year,month);break;
              case 4:
              case 6:
              case 9:
              case 11:printf("the days of %d of %d is 30",year,month);break;
              default:printf("error input!\n");
      }
    }
 }
2018-04-16 21:46
nosnoy
Rank: 9Rank: 9Rank: 9
来 自:mcu
等 级:贵宾
威 望:14
帖 子:541
专家分:1178
注 册:2016-9-17
收藏
得分:0 
强迫症患者的版本
#include<stdio.h>
 void main()
 {
     int year,month;
     printf("input year and month:");
     scanf("%d%d",&year,&month);
      switch(month)
          {
              case 1:printf("the days of %d of %d is 31",year,month);break;
              case 2:
                     if((year%4==0&&year%100!=0)||(year%400==0))
                      printf("the days of %d of %d is 29",year,month);
                      else printf("the days of %d of %d is 28",year,month);
                        break;
              case 3 :printf("the days of %d of %d is 31",year,month);break;
              case 4 :printf("the days of %d of %d is 30",year,month);break;
              case 5 :printf("the days of %d of %d is 31",year,month);break;
              case 6 :printf("the days of %d of %d is 30",year,month);break;
              case 7 :printf("the days of %d of %d is 31",year,month);break;
              case 8 :printf("the days of %d of %d is 31",year,month);break;
              case 9 :printf("the days of %d of %d is 30",year,month);break;
              case 10:printf("the days of %d of %d is 31",year,month);break;
              case 11:printf("the days of %d of %d is 30",year,month);break;
              case 12:printf("the days of %d of %d is 31",year,month);break;      
              default:printf("error input!\n");
      }
    }
 }

[此贴子已经被作者于2018-4-17 09:29编辑过]


穷举是最暴力的美学
2018-04-17 09:26
快速回复:请教一下,这个关于switch的语句~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018387 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved