不算太难的C语言题,求完整代码,完成后至少给50鱼币,谢谢!
本帖最后由 1molHF 于 2021-12-6 18:23 编辑题目及要求见附件。我被要求从10道基本题和7道进阶题中任选3道,对大佬来说这些题应该不难,但我实在太菜了,想了很久都没有思路。恳请大家做完3道后发一下每一道题的完整代码,谢谢!
如果做了进阶题,我就在50鱼币的基础上再给30鱼币。由于我的等级低,没法一次性给50、80鱼币,所以我会再发几个帖子专门给解决我问题的人鱼币.
本帖最后由 傻眼貓咪 于 2021-12-6 21:43 编辑
2.3 万年历#include <stdio.h>
#include <stdbool.h>
bool isLeap(int y){ return ((!(y%4)) && (y%100)) || (!(y%400)); }
int ZellersCongruence(int d, int m, int y){
if(m < 3){ m += 12; y --; }
int h = (d + (13*(m+1))/5 + (y%100) + (y%100)/4 + (y/100)/4 - 2*(y/100))%7;
return ((h + 5)%7) + 1;
}
void calendar(int h, int m, int y){
/* h: day of the week for first day in the month */
h %= 7;
char* w = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
printf("%s %d\n", w, m);
printf("====================\n");
printf(" SMTWTFS\n");
int n = 1;
int d = m == 2 && isLeap(y) ? 29 : m == 2 ? 28 : ((m < 8) && (m % 2)) || ((m > 7) && !(m % 2))? 31 : 30;
for(size_t i = 0; i < h; i++, n++) printf("%2s ", "");
for(size_t i = 1; i <= d; i++, n++){
printf("%2ld ", i);
if(!(n % 7)) printf("\n");
}
printf("\n====================\n");
}
void calendar_of_the_year(int y){
for(int m = 1; m < 13; m++){
int h = ZellersCongruence(1, m, y);
calendar(h, m, y);
printf("\n");
}
}
int weeks(int day, int month, int year){
int days = day;
for(int m = 1; m < month; m++) days += (m == 2 && isLeap(year) ? 29 : m == 2 ? 28 : ((m < 8) && (m % 2)) || ((m > 7) && !(m % 2))? 31 : 30);
return days/7 + 1;
}
int main(){
while(1){
int date = {0}, d, m, y, h, a, b;
char* w = {"", "一", "二", "三", "四", "五", "六", "日"};
for(int i = 0; i < 3; i++){
scanf("%d", &date);
if(getchar() == '\n') break;
}
if(!date) break;
int code = !date ? 0 : !date ? 1 : date > date ? 2 : 3;
switch(code){
case 0:
y = date;
calendar_of_the_year(y);
break;
case 1:
y = date;
m = date;
h = ZellersCongruence(1, m, y);
calendar(h, m, y);
break;
case 2:
y = date;
m = date;
d = date;
h = ZellersCongruence(1, m, y);
calendar(h, m, y);
a = weeks(d, m, y);
b = ZellersCongruence(d, m, y);
printf("该日期属于本年的第 %d 周,星期%s\n", a, w);
break;
case 3:
m = date;
d = date;
y = date;
h = ZellersCongruence(1, m, y);
calendar(h, m, y);
a = weeks(d, m, y);
b = ZellersCongruence(d, m, y);
printf("该日期属于本年的第 %d 周,星期%s\n", a, w);
break;
}
}
return 0;
}**因为实在是忍不住,所以不知不觉做完一题,哈哈哈 傻眼貓咪 发表于 2021-12-6 21:36
2.3 万年历**因为实在是忍不住,所以不知不觉做完一题,哈哈哈
谢谢大佬!你在我发的两个感谢帖后回复我,就能得到17鱼币 傻眼貓咪 发表于 2021-12-6 21:36
2.3 万年历**因为实在是忍不住,所以不知不觉做完一题,哈哈哈
我的两个感谢帖主题都设置为技术交流
页:
[1]