旅行社设立申请书范文:输入年份,输出该年是否为闰年。

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 22:10:18
麻烦高手解一下,用什么语言都行
输入年份,输出该年是否为闰年。

Visual Basic 语言

private sub form_load()
a = val(inputbox("输入年份"))
if len(a)<>4 then
msgbox"请输入正确的年份"
end
else
if a mod 400 = 0 then
msgbox"是闰年"
end
elseif a mod 4 = 0 and a mod 100 <> 0 then
msgbox"是闰年"
end
else
msgbox"不是闰年"
end
endif
endif
end sub

闰年的条件是1.能被4整除,但不能被100整除.2.能被100整除,又能被400整除.
main()
{
int year,leap;
scanf("%d",&year);
if(year%4==0)
{if(year%100==0)
{if(year%400==0)
leap=1;
else leap=0;}
else
leap=1;}
else
leap=0;
if(leap)
printf("%d is",year);
else
printf("%d is not",year);
printf("a leap year,\n");
}

c语言:
闰年的条件是符合下面两个条件之一:
1。能被4整除,但不能被100整除。
2。能被400整除。

main(){
int year;
scanf("%d",&year);
if((year%4==0&&year%100!=0)||year%400==0)
printf("%d 是闰年 ",year);
else
printf("%d year 不是闰年",year);
}


关键是判断闰年的条件得记着!

都对都对

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{int i;
cout<<"请输入一个年份"<<endl;
cin>>i;
cout<<"你输入的年份是:"<<i<<endl;
if (i % 400==0||(i % 100!=0 && i % 4==0))
cout<<i<<"年是闰年"<<endl;
else
cout<<i<<"年不是闰年"<<endl;
system("pause");
}

工具:dev c++