java中12个月_C中的12个月日历
我用C做了12个月的日历 . 这个程序显示特定年份的12个月日历 . 该程序提示用户打印年份,并计算出(a)年份是否为闰年,以及(b)所选年份的哪一天开始 .
说明:
•main()提示用户输入,调用您自己设计的函数来确定输入年份的开始日期 . 然后它调用函数printCalendar()来实际打印十二个月的日历 .
•printCalendar()有两个参数,年份编号和开始日期 . 然后循环遍历年份并调用函数printMonth()十二次,每个月一次 .
•printMonth()接受三个参数,即年份编号,月份编号和特定月份的开始日期,它返回下个月开始的日期编号 . 打印月必须首先调用函数printMonthName(),然后以日历格式打印出月中的日期 .
•printMonthName()将年份编号和月份编号作为参数,打印出标识月份的行,并返回该月份的天数,同时考虑闰年 .
我按照这些说明进行了操作:
#include
#include
int daysInMonth;
int getDayCode(int year);
void printCalendar(int year, int dayCode);
int getYear(void);
int getYear(void){
int year;
printf("Please enter a year: ");
scanf("%i", &year);
printf("\n");
return year;
}
int getDayCode(int year){
int dayCode;
int x1, x2, x3;
x1 = (year - 1.)/ 4.0;
x2 = (year - 1.)/ 100.;
x3 = (year - 1.)/ 400.;
dayCode = (year + x1 - x2 + x3) %7;
return dayCode;
}
main(){
int year, dayCode;
year = getYear();
dayCode = getDayCode(year);
printCalendar(year, dayCode);
}
void printCalendar(int year, int dayCode){
int month;
printf(" %d Monthly Calendar\n", year);
printf(" \n");
printf(" \n");
for (month = 1; month <= 12; month++){
printMonth(year, month, dayCode);
}
}
int printMonthName(int year, int month){
switch (month){
case 1:
printf("\n\nJanuary %i", year);
daysInMonth = 31;
return daysInMonth;
break;
case 2:
printf("\n\nFebruary %i", year);
if (year%4 == 0 && year%100 != 0 || year%400 == 0){
//printf("This is a leap year.\n");
daysInMonth = 29;
return daysInMonth;
}
else{
//printf("This is not a leap year.\n");
daysInMonth = 28;
return daysInMonth;
}
break;
case 3:
printf("\n\nMarch %i", year);
daysInMonth = 31;
return daysInMonth;
break;
case 4:
printf("\n\nApril %i", year);
daysInMonth = 30;
return daysInMonth;
break;
case 5:
printf("\n\nMay %i", year);
daysInMonth = 31;
return daysInMonth;
break;
case 6:
printf("\n\nJune %i", year);
daysInMonth = 30;
return daysInMonth;
break;
case 7:
printf("\n\nJuly %i", year);
daysInMonth = 31;
return daysInMonth;
break;
case 8:
printf("\n\nAugust %i", year);
daysInMonth = 31;
return daysInMonth;
break;
case 9:
printf("\n\nSeptember %i", year);
daysInMonth = 30;
return daysInMonth;
break;
case 10:
printf("\n\nOctober %i", year);
daysInMonth = 31;
return daysInMonth;
break;
case 11:
printf("\n\nNovember %i", year);
daysInMonth = 30;
return daysInMonth;
break;
case 12:
printf("\n\nDecember %i", year);
daysInMonth = 31;
return daysInMonth;
break;
default:
printf("Invalid input! Please try again!\n");
break;
}
}
int printMonth(int year, int month, int dayCode){
int day;
printMonthName(year, month);
printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );
/* advance printer to correct position for first date */
for (day = 1; day <= 1 + dayCode * 5; day++)
printf(" ");
/* print the dates for one month */
for (day = 1; day <= daysInMonth; day++){
printf("%2d", day);
if ((day + dayCode) % 7 > 0) /* before Sat? */
/* move to next day in same week */
printf(" ");
else /* skip to next line to start with Sun */
printf("\n ");
}
/* set day_code for next month to begin */
dayCode = (dayCode + daysInMonth % 7);
return dayCode;
}
我把2013年作为输入年份,我的代码从星期二的1月1日开始,这是正确的 . 但它也是在周二开始的所有12个月,这是问题所在:Calendar Output 2013
请帮忙 . 我一直试图让这个工作很长一段时间 .
java中12个月_C中的12个月日历相关推荐
- java有没有友元函数_c++中友元函数理解与使用
在学习c++这一块,关于友元函数和友元类,感觉还是不好理解,但是井下心来,理解,需要把我一下几点. 首先讲友元函数. (1)友元函数: 1)C++中引入友元函数,是为在该类中提供一个对外(除了他自己意 ...
- java 快排非递归_C++ 中快排的递归和非递归实现
快排的递归 void quickSort1(int* root,int low,int high) { int pat=root[low]; if(low { int i=low,j=high; wh ...
- python展开 c函数中的宏预处理_C中的预处理宏
C中的预处理宏 宏定义就属于预处理命令的一种.那么,什么是宏呢? 宏:c语言标准允许在程序中用一个标识符来表示一个字符串.标识符就是宏名. 宏替换:宏替换就是宏定义.在编译预处理中,将程序中所有的宏名 ...
- c++中的结构体_C ++中的结构
c++中的结构体 介绍 (Introduction) In this tutorial, we are going to learn the basics of Structures in C++, ...
- c语言中++b与b++_C ++中的朋友功能
c语言中++b与b++ Friend Functions in C++ are a category of functions that can access private and protecte ...
- c ++中字符串长度的_C ++中的字符串长度
c ++中字符串长度的 The string length in C++ can be calculated or found by various methods. Here, in this tu ...
- 中国医科大学2021年12月《中医护理学基础》作业考核试题
中国医科大学2021年12月<中医护理学基础>作业考核试题 试卷总分:100 得分:100 一.单选题 (共 20 道试题,共 20 分) 1.根据地理环境的不同,来确定治疗.护理的原则的 ...
- java 挥发注解_C中的挥发性预选赛
java 挥发注解 什么是C中的限定词? (What is Qualifiers in C?) Qualifiers in C are the keywords which are used to m ...
- java当中有关循环的代码_有关Java循环的内容,编程中还是比较常用的,下面分享给大家几个循环的示例代码,练习一下。1、循环输出1到100之间所有能被3或能被4整除的数。pack...
有关Java循环的内容,编程中还是比较常用的,下面分享给大家几个循环的示例代码,练习一下. 1.循环输出1到100之间所有能被3或能被4整除的数. package com.hz.loop02; /** ...
- java 日历工具_java中强大的时间处理工具:Calendar类(日历类)
java中的Calendar类为什么起个名字就叫做日历呢?因为这个类可以让我们像看日历一样得到这个时间的所有属性,你还在为不知道2014年5月7日是周几而苦恼吗?你还在为2005年8月14日是8月的第 ...
最新文章
- 自定义类型数组的初始化
- Python判断 子集
- CSS学习04之层次选择器
- linux如何关闭 lvm管理,Linux之LVM管理
- r语言清除变量_R语言(1)初识与数据结构
- 基于androidx的快速开发框架_Vue企业级优雅实战07框架开发03封装基于MockJS的模拟数据...
- CSS 元素的绝对定位 position: absolute 和 position: fixed
- 计算机系统还原到某个时间节点,电脑恢复到某个时间点
- C/C++——set的基本操作总结
- nodeJS之repl
- websocket协议与实现原理
- 螺旋矩阵常数复杂度解法
- adguard home上网慢_AdGuardHome最新版本DNS设置负载均衡设置讨论:哪种设置快
- 如何在Linux终端查询修改主机名、以及主机名与ip的映射关系?
- 文本深度表示模型——word2vecdoc2vec词向量模型(转)
- Linux I2C总线(二)I2C设备驱动编写方法
- [react] redux react-redux
- Linux战地日记—date命令详细示例
- MySQL 分库分表实践
- xfire webservice 实例
热门文章
- Electron 应用实战 (架构篇)
- 二 、 搭建Android 开发环境读书笔记
- 【原创】Mapped Statements collection does not contain value for DaoImpl.method
- 转 自定义View之onMeasure()
- 点点滴滴——变量对象的产生
- SpringCloud之Ribbon源码分析(一)
- 【Spring-AOP】自动代理类AnnotationAwareAspectJAutoProxyCreator
- JAVA中Random分析
- css 固定宽度,自动换行
- 不可不知的socket和TCP连接过程