rmml.net
当前位置:首页 >> C语言:从键盘上输入一个日期,判断输入的日期是否正确 >>

C语言:从键盘上输入一个日期,判断输入的日期是否正确

定义一个12元素的int型数组存放1月份至12月份每个月的天数; 根据输入的年份判断是否为闰年,对上述数组中2月份的天数进行调整; 判断年份大于0、月份大于0小于13、日期大于0小于等于月份对应的天数为正确输入,否则为错误输入。 代码如下: #in...

思路:所谓闰年就是能被4整除不能被100整除或者能被400整除,可以先定义一个函数判断一个数是否是闰年,接着键盘输入并判断输出。 参考代码: #includeint fun(int year){//判断year是否是闰年 if((year%4==0&&year/100!=0)||(year%400==0))retu...

#include #include int main(){ char stime[20]; scanf("%s",stime); if(strcmp(stime,"11:00")

#include int main(void) { int month,year,day,sum,i=0; printf("输入年月日:\n"); scanf("%d %d %d",&year,&month,&day); switch(month) { case 12: i=i+30; case 11: i=i+31; case 10: i=i+30; case 9: i=i+31; case 8: i=i+31; case 7: i=i+...

#include int monthsize(int year,int month) {int days;if(month == 2) {if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)return 29;return 28;}switch(month) {case 1 :case 3 :case 5 :case 7 :case 8 :case 10 :case 12 :days = 31...

#include int main(){ int s[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31, 0,31,29,31,30,31,30,31,31,30,31,30,31,}; int year=0; int month=0; int day=0; int n,i,daytemp; int flag=0; int nyear=0,nmonth=0,nday=0; printf("输入年月日...

#include void main() { int year,month,day=0,a,b,week,c,i,sum=0,days,d; printf("please input year,month,days\n"); scanf("%d,%d,%d",&year,&month,&days); for(i=1;i

#include int main() { int i,score; printf("Enter Grade: \n"); scanf("%d",&score); switch(score/60){ case 1:printf("Pass\n");break; case 0:printf("Fail\n");break; } return 0; } /* 输出: Enter Grade: 59 Fail */

#include "stdio.h"#include "conio.h"void main(){ int day,month,year,sum,leap; printf("\nplease input year,month,day\n"); scanf("%d,%d,%d",&year,&month,&day); switch(month) /*先计算某月以前月份的总天数*/ { case 1:sum=0;break; ca...

#include void main ( ) { int year,leap; printf ("Please enter year:\n"); scanf ("%d",&year); if (year%400==0) leap=1; else if ((year%4==0)&&(year%100!=0)) leap=1; else leap=0; if (leap!=0) printf ("%d is a leap year.\n",year); ...

网站首页 | 网站地图
All rights reserved Powered by www.rmml.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com