#include <stdio.h> struct nian{ int year, month, day; }; int main(void) { struct nian i; int j, t; int sum = 0; int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; scanf("%d %d %d",&i.year, &i.month, &i.day); for(j = 0; j < i.month - 1; j++){ sum += a[j]; } t = sum + i.day; if(i.month > 2){ if(i.year % 4 == 0 && i.year % 100 != 0 || i.year % 400 == 0){ t++; } } printf("%d\n",t); return 0; }
#include<stdio.h> struct arr { int Year; //年 int Monht; //月 int Day; //日 }p; int main() { int a[13] = { 31,29,31,30,31,30,31,31,30,31,30,31 };//a[13]在我的编译器中会越界,当然也可以写a[12+1]留一个\n位置 scanf("%d %d %d", &p.Year, &p.Monht, &p.Day); if (p.Year % 4 == 0 && p.Year % 100 != 0 || p.Year % 400 == 0) { int j = 0; p.Monht--;减去输入的最后一个月,输入的天数代替 for (int i = 0; i < p.Monht; i++) { j += a[i]; } j += p.Day;天数 printf("%d",j); } else { int j = 0; p.Monht--; for (int i = 0; i < p.Monht; i++) { j += a[i]; } j += p.Day; j--;//平年比闰年少一天 printf("%d", j); } } return 0;
#include <stdio.h> int nian(int year) { return year % 400 ? ((year % 4) ? 0 : 1 ) : 1; } struct t { int year; int month; int day; } ; int main() { int w; struct t sc; int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; scanf("%d %d %d", &sc.year, &sc.month, &sc.day); for (int i = 0; i < sc.month - 1; i++) { w += months[i]; } w += sc.day; if ((nian(sc.year) && sc.month > 2)) w++; printf("%d\n", w); return 0; }//为什么代码运行结果没问题但是过不了,显示答案错误
悠游 2023-08-30 15:23:15 |
用来计数的记得赋0,要养成习惯,int w=0;还有三目运算符那段呃,return year%100 ? ((year%4) ? 0:1):((year%400)? 0:1);这么写更符合点吧(╹ڡ╹ )(╹ڡ╹ )
#include<stdio.h> struct date { int year; int month; int day; }; int mian() { struct date a; int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int sum=0; scanf("%d%d%d",&a.year,&a.month,&a.day); if(year%400==0||year%4==0&&year%100!=0)//为闰年 { a[1]=29;//第二个月 } for(int i=0;i<a.month-1;i++)//如果3月,则天数为一月加二月的总天数,再加上三月的日期。 { sum=sum+a[i];// 加前面完全过了的月份 } sum=sum+a.day;//加上这个月的天数。 printf("%d",sum); return 0; }请问这个为什么不对呀?
菜鸡的小刘 2023-05-05 20:39:04 |
main写错了,你起码要能运行呀
#include<stdio.h> struct demo{ int year; int month; int day; }; int main(){ struct demo a; scanf("%d%d%d",&a.year,&a.month,&a.day); int b[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int sum=0,i; for(i=0;i<a.month-1;i++){ sum=sum+b[i]; } sum=sum+a.day; if(a.year%400==0||(a.year%4==0&&a.year%100!=0)){ sum=sum+1; } printf("%d",sum); return 0; }
#include <stdio.h> int main() { struct date { int year; int month; int day; }; struct date a; int sum = 0; scanf("%d%d%d", &a.year, &a.month, &a.day); for (int i = 1; i <= a.month; i++) { if (i == a.month) { sum += a.day; } else { switch (i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: sum += 31; break; case 2: if ((a.year % 4 == 0 && a.year % 100 != 0) || a.year % 400 == 0) sum += 29; else sum += 28; break; case 4: case 6: case 9: case 11: sum += 30; break;
#include <stdio.h> #include <stdlib.h> #include <string.h> struct str{ int year; int month; int day; };//注意这里的结尾处冒号 int isleapyear(int x); void main() { int sum=0; struct str stu; scanf("%d %d %d", &stu.year,&stu.month,&stu.day); int arr[12]={31,28,31,30,31,30,31,31,30,31,30,31}; for(int i=0;i<stu.month-1;i++) { sum+=arr[i]; } if(isleapyear(stu.year)) sum=sum+stu.day+1; else sum=sum+stu.day; printf("%d",sum); system("pause"); } int isleapyear(int x) { if(x%4==0 && x%100==0 || x%400==0) return 1; else
【金明的预算方案】 (C++代码)浏览:996 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:897 |
母牛的故事 (C语言代码)浏览:739 |
字符逆序 (C语言代码)浏览:645 |
a+b浏览:452 |
1113题解浏览:823 |
1024题解浏览:879 |
妹子杀手的故事 (C语言代码)浏览:1153 |
链表数据求和操作 (C语言代码)浏览:1035 |
C语言训练-自守数问题 (C语言代码)浏览:798 |