ZKX's LAB

输入某年某月判断是是第几天 输入某年某月某日,判断这一天的下一天是几月几号

2021-04-24知识1

编程:输入某年某月某日,判断这一天是这一年的第几天 include<;iostream>;using namespace std;bool isLeapYear(int y);声明bool inputRight(int y,int m,int d);声明/定义日期结构体,包括年、月、日struct { int year;年 int 。

输入某年某月某日,判断这一天是这一年的第几天? import java.util.*;public class test{public static void main(String[]args){Scanner in=new Scanner(System.in);System.out.println(\"请输入年:\");int year=in.nextInt();System.out.println(\"请输入月:\");int month=in.nextInt();System.out.println(\"请输入日:\");int day=in.nextInt();int m=0;int days=0;int[][]a={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};if((year%4=0&year%100。0)|year%400=0){m=1;}else{m=0;}for(int i=0;i;i+){days+a[m][i];}days+day;System.out.println(\"这天是:\"+year+\"年的第\"+days+\"日\");}}

题目:输入某年某月某日,判断这一天是这一年的第几天? 下面是我改的你的程序,有问题的地方我加了注释了,你可以跟你以前的对比一下。可以运行,能正确判断闰年的天数。includeint main(){int year,month,day,sum=0,leap;printf(\"输入某年某月某日:\");scanf(\"%d%d%d\",&year,&month,&day);容易粗心输入格式错误,就把%d后面的逗号去了。switch(month){case 1:sum=0;break;case后的应该是数字而不是字符,也就是数字没有单引号case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf(\"输入错误\");break;}sum=sum+day;if(year%400=0|(year%4=0&year%100。0))leap=1;elseleap=0;if(leap=1&month>;2)/判断leap是否为1应为:leap=1,而不是赋值leap=1。sum+;printf(\"%d\\n\",sum);}

#输入某年某月判断是是第几天

随机阅读

qrcode
访问手机版