3137:【例23.2】 这个月有几天
C语言代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int y,m;
scanf("%d%d",&y,&m);
int a[12+1]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if( m!=2 )
{
printf("%d\n",a[m]);
}
else
{
if( (y%4==0 && y%100!=0) || y%400==0 )
{
printf("%d\n",(a[m]+1) );
}
else
{
printf("%d\n",a[m]);
}
}
return 0;
}
C++代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int y,m;
cin>>y>>m;
int a[12+1]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if( m!=2 )
{
cout<<a[m]<<endl;
}
else
{
if( (y%4==0 && y%100!=0) || y%400==0 )
{
cout<<a[m]+1<<endl;
}
else
{
cout<<a[m]<<endl;
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int y,m,a=28;
cin>>y>>m;
if((y%4==0&&y%100!=0)||y%400==0)a=29;
switch(m)
{
case 1:cout<<"31";break;
case 2:cout<<a;break;
case 3:cout<<"31";break;
case 4:cout<<"30";break;
case 5:cout<<"31";break;
case 6:cout<<"30";break;
case 7:cout<<"31";break;
case 8:cout<<"31";break;
case 9:cout<<"30";break;
case 10:cout<<"31";break;
case 11:cout<<"30";break;
case 12:cout<<"31";break;
}
return 0;
}
#include<iostream>
using namespace std;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int y,m;
cin>>y>>m;
if(m==2){
if(y%4==0&&y%100!=0){
cout<<29;
}
else if(y%400==0) {
cout<<29;
}
else{
cout<<28;
}
}
else cout<<a[m];
return 0;
}
python算法和数据结构书籍(二)
啊哈算法(python)
啊哈算法系列(C语言、python、Java )
从Scratch到C++ 从Scratch到python书籍
python画图、python小游戏、python刷题、python算法、python编程与数学
python画图、python小游戏、python刷题、python算法、python编程与数学_pygame 小学数学-CSDN博客