#include<stdio.h> #include<math.h> int main() { int sum; struct { int y; int m; int d; }a; scanf("%d%d%d",&a.y,&a.m,&a.d); switch (a.m) { case 1: sum=a.d;break; case 2: sum=31+a.d;break; case 3: sum=31+28+a.d;break; case 4: sum=31+28+31+a.d;break; case 5: sum=31+28+31+30+a.d;break; case 6: sum=31+28+31+30+31+a.d;break; case 7: sum=31+28+31+30+31+30+a.d;break; case 8: sum=31+28+31+30+31+30+31+a.d;break; case 9: sum=31+28+31+30+31+30+31+31+a.d;break; case 10: sum=31+28+31+30+31+30+31+31+30+a.d;break; case 11: sum=31+28+3
#include<stdio.h> struct create{ // 声明结构体类型 int year; int month; int day; }; int main(){ struct create date; int y=date.year; int m=date.month; int d=date.day; //这里就类似于Java中定义了一个类string那种感觉; int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int sum=0; //都进行初始化 scanf("%d %d %d",&y,&m,&d); if(y%4==0&&y%100!=0||y%400==0){ a[1]=29;//如果是闰年的话 2月份就是29天 } else { //平年28天 a[1]=28; } for(int i=0;i<m-1;i++){ //这里有12个月 被m给控制着; 比如month输入的是6 因为数组是从0开始 6-1=5 前面5个 sum+=a[i]; } sum+=d; //将这个月的天数加上; printf("%d",sum); return 0; }
stolen 2022-05-25 09:55:23 |
作者很棒诶~容易理解
#include<stdio.h> int main() { struct time{ int year; int mon; int day; }t; int *c; scanf("%d %d %d",&t.year,&t.mon,&t.day); int mons[12]={31,28,31,30,31,30,31,31,30,31,30,31},sum=0,i; for(i=0;i<t.mon-1;i++)sum+=mons[i]; sum+=t.day; if(((t.year%4==0)&&(t.year%100!=0)||(t.year%400==0))&&(t.mon>2))sum++; printf("%d",sum); return 0; }//各位大佬看看我写的咋样
为什么是m-1?
学c学到秃头 2022-05-13 18:55:18 |
#include<stdio.h> int main() { struct time{ int year; int mon; int day; }t; int *c; scanf("%d %d %d",&t.year,&t.mon,&t.day); int mons[12]={31,28,31,30,31,30,31,31,30,31,30,31},sum=0,i; for(i=0;i<t.mon-1;i++)sum+=mons[i]; sum+=t.day; if(((t.year%4==0)&&(t.year%100!=0)||(t.year%400==0))&&(t.mon>2))sum++; printf("%d",sum); return 0; }
学c学到秃头 2022-05-13 18:55:30 |
看看我写的
杨静初 2022-05-14 22:16:55 |
啊这。。个格式emmm
在路上 2022-11-01 17:26:20 |
因为i是从零开始的所以要减一
heart 2022-12-16 14:35:53 |
因为要这里统计的是m月之前的月份天数,比如m=5 前四个月不就是0123么
//定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天,注意闰年问题。 #include<stdio.h> int main(void) { struct time { int year; int month; int day; }oneday; scanf("%d", &oneday.year); scanf("%d", &oneday.month); scanf("%d", &oneday.day); int monthday = 0, i = 1, j = 1; for (i = 1; i < oneday.month; i++) { if (i % 2 == 1) { monthday += 31; } else if (i % 2 == 0 && i != 2) { monthday += 30; } else if (i == 2&&oneday.year%4==0&&oneday.year%400==0) { monthday += 29; } else { monthday += 28; } } int ans = 0; ans = monthday + oneday.day; printf("%d", ans); } 哇 这个看不出什么错 服了
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:589 |
C语言程序设计教程(第三版)课后习题9.4 (Java代码)浏览:1446 |
兰顿蚂蚁 (C++代码)浏览:1225 |
简单的a+b (C++语言代码)浏览:895 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:903 |
Tom数 (C语言代码)浏览:598 |
剪刀石头布 (C语言代码)浏览:1519 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:536 |
敲七 (C++代码)浏览:1119 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:594 |
乐观塔达 2022-09-05 16:27:51 |
有想法,但不多
坚果 2022-12-27 12:34:52 |
#include<stdio.h> #include<string.h> int main() { struct time { int year; int mon; int day; }t; int sum=0; scanf("%d %d %d",&t.year,&t.mon,&t.day); switch(t.mon) { case 12:sum=sum+t.day; case 11: if(t.mon>11) sum=sum+30; else sum=sum+t.day; case 10: if(t.mon>10) sum=sum+31; else sum=sum+t.day; case 9: if(t.mon>9) sum=sum+30; else sum=sum+t.day; case 8: if(t.mon>8) sum=sum+31; else sum=sum+t.day; case 7: if(t.mon>7) sum=sum+31; else sum=sum+t.day; case 6: if(t.mon>6) sum=sum+30; else sum=sum+t.day; case 5: if(t.mon>5) sum=sum+31; else sum=sum+t.day; case 4: if(t.mon>4) sum=sum+30; else sum=sum+t.day; case 3: if(t.mon>3) sum=sum+31; else sum=sum+t.day; case 2: if((t.year%4==0&&t.year%100!=0)||t.year%400==0) sum=sum+29; else sum=sum+28; case 1: if(t.mon>1) sum=sum+31; else sum=sum+t.day; }//不跳出循环 printf("%d",sum); return 0; }
明月几时有 2023-01-02 16:08:31 |
#include<stdio.h> typedef struct Time { int year; int month; int day; }Time; int calculation_date(Time *pdate) { int num,a; // 判断2月多少天 if(pdate->year%4==0) { a=29; } else { a=28; } //计算不同月份的天数 switch(pdate->month) { case 1:num=pdate->day;break; case 2:num=31+pdate->day;break; case 3:num=31+a+pdate->day;break; case 4:num=31+a+30+pdate->day;break; case 5:num=31+a+30+31+pdate->day;break; case 6:num=31+a+30+31+30+pdate->day;break; case 7:num=31+a+30+31+30+31+pdate->day;break; case 8:num=31+a+30+31+30+31+31+pdate->day;break; case 9:num=31+a+30+31+30+31+31+30+pdate->day;break; case 10:num=31+a+30+31+30+31+31+30+31+pdate->day;break; case 11:num=31+a+30+31+30+31+31+30+31+30+pdate->day;break; case 12:num=31+a+30+31+30+31+31+30+31+30+31+pdate->day;break; } return num; } int main() { int num; Time date; scanf("%d %d %d",&date.year,&date.month,&date.day); Time *p=&date; num=calculation_date(p); printf("%d ",num); return 0; }