[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
A. 实验5-4 输出每个月的天数 题目描述
本题要求实现一个简单函数,能计算给定的年份和月份的天数。使得可以利用该函数,输出给定年份中每个月的天数。其中1、3、5、7、8、10、12月有31天,4、6、9、11月有30天,2月平年有28天,闰年有29天。
要求定义并调用函数month_days(year,month),该函数返回year年month月的天数。 输入 年year 输出 该年1~12月每个月的天数
样例查看模式 正常显示 查看格式 输入样例1 2000 输出样例1 31 29 31 30 31 30 31 31 30 31 30 31
这道题没什么好说的
就是使用全局变量把函数的所有月份返回值记录并输出
int m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12; int year_(int y) {
if(y%4==0&&y%100!=0||y%400==0) return 1; else return 0; } void month_days(int
year) { if(year_(year)==1) {
m1=31;m2=29;m3=31;m4=30;m5=31;m6=30;m7=31;m8=31;m9=30;m10=31;m11=30;m12=31; }
else {
m1=31;m2=28;m3=31;m4=30;m5=31;m6=30;m7=31;m8=31;m9=30;m10=31;m11=30;m12=31; } }
#include<stdio.h> int main() { int year; scanf("%d",&year); month_days(year);
printf("%d %d %d %d %d %d %d %d %d %d %d
%d",m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12); return 0; }