| 网站首页 | 业界新闻 | 群组 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 218 人关注过本帖
标题:请教一下,这个关于switch的语句~
只看楼主 收藏
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-4-15
结帖率:100%
  已结贴   问题点数: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
2018-04-15 16:35
ab1412
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:37
专家分:134
注 册: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");
  }
 }



错的地方有点多,我就不一一说了,帮你改好了自己看吧
2018-04-15 16:57
a451410
Rank: 2
等 级:论坛游民
帖 子:14
专家分:24
注 册:2018-3-4
  得分:0 
printf不是prtinf  基本的输出函数要记清楚!  !=(不等于要这样写),不能写成!==   
基本的单词要记住。
2018-04-15 17:05
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-4-15
  得分:0 
回复 2楼 ab1412
谢谢您哈~
2018-04-15 17:48
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-4-15
  得分:0 
回复 3楼 a451410
一时疏忽。。Thanks♪(・ω・)ノ蟹蟹~
2018-04-15 17:49
欧讷河文
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2018-3-28
  得分:0 
回复 2楼 ab1412
你这个输2月份有问题的  不是天数问题 是后面跟着error input!
7 天前 18:24
孤傲晴天
Rank: 1
等 级:新手上路
帖 子:1
专家分: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");
      }
    }
 }
7 天前 21:46
nosnoy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:127
专家分:181
注 册: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编辑过]

6 天前 09:26







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

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