代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
计算输入的日期是当年的第几天,包括对输入错误时的检
作者:
王维来
/ 发布于
2015/8/3
/
1420
计算输入的日期是当年的第几天,包括对输入错误时的检测。VC2010环境下的程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 // cout_date.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "count_date.h" int _tmain(int argc, _TCHAR* argv[]) { int work = 1; int count = 0; int YearHandle(); //YearHandle() function declaration int MonthHandle(); //MonthHandle() function declaration int DayHandle(); //DayHandle() function declaration while(work) { s.year =0; s.month =0; s.day =0; count =0; system("cls"); //clear the screen. system("color 7c"); //set the color of background. printf("\n--------------------------Welcome To The Count System--------------------------\n"); putchar('\n'); s.year = YearHandle(); s.month = MonthHandle(); s.day = DayHandle(); for(int i=1; i<s.month; ++i) { count+=yearArray[sign][i]; //count the day. } count+=s.day; printf("The %d/%d/%d is the %dth of this year!\n", s.year, s.month, s.day, count); //ouput the relut. putchar('\n'); printf("Whether exit the count system?(1 is not exit,0 is exit)\n"); //whether exit the system. scanf("%d", &work); fflush(stdin); while (work!=0 && work!=1) //kik must is 1 or 0. { printf(" Input is error,Please input again!\n"); scanf("%d", &work); fflush(stdin); } } printf("\n--------------------Thanks For You Using The Count System !--------------------\n"); Sleep(2000); //deley some times. return 0; } /* YearHandle() function to enter the year and check*/ int YearHandle() { bool kos = 0; bool Check_digit(char *kk); printf("Please input the year: "); char year[10]={0}; gets(year); putchar('\n'); kos = Check_digit(year); s.year = atoi(year); while((s.year<=1000 || s.year>=9000) || kos) // input the year must between in 1000 to 9000. { printf("The year is error, Please input again!\n"); printf("Please input the year: "); gets(year); putchar('\n'); kos = Check_digit(year); s.year = atoi(year); } return s.year; } /* MonthHandle() function to enter the month and check*/ int MonthHandle() { bool kos = 0; bool Check_digit(char *kk); printf("Please input the month: "); char month[10]={0}; gets(month); putchar('\n'); kos = Check_digit(month); s.month = atoi(month); while(s.month<1 || s.month>12 || kos) //input the month must between in 1 to 12. { printf("The month is error,Please input again!\n"); printf("Please input the month: "); gets(month); putchar('\n'); kos = Check_digit(month); s.month = atoi(month); } return s.month; } /* DayHandle() function to enter the day and check*/ int DayHandle() { bool kos = 0; bool Check_digit(char *kk); printf("Please input the day: "); char day[10]={0}; gets(day); putchar('\n'); kos = Check_digit(day); s.day = atoi(day); sign = ((s.year%4==0) && (s.year%100!=0) || (s.year%400==0)); //judge the leap year. while(s.day <1 || s.day>yearArray[sign][s.month] || kos) //the day must in the month. { printf("The day is error,Please input again!\n"); printf("Please input the day: "); gets(day); putchar('\n'); kos = Check_digit(day); s.day = atoi(day); } return s.day; } /*Check_digit() function to check whether the input is a number*/ bool Check_digit(char *kk) { int a = strlen(kk); for(int i=0; i<a; ++i) { if(((int)(*(kk+i)) < 48) || ((int)(*(kk+i)) > 57)) { return 1; } } return 0; } #include "stdafx.h" #include "stdlib.h" #include "windows.h" #define UNCHAR unsigned char UNCHAR yearArray[2][13] = { /* 0 1 2 3 4 5 6 7 8 9 10 11 12 */ {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; struct //defining the time structure { int year; int month; int day; }s={0,0,0}; bool sign = 0;
试试其它关键字
第几天
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
王维来
贡献的其它代码
(
3
)
.
计算输入的日期是当年的第几天,包括对输入错误时的检
.
利用二维动态数组指针做矩阵运算
.
清理垃圾
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3