|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 baivip 于 2019-4-1 20:29 编辑
1 #include <stdio.h>
2
3 int main()
4 {
5 unsigned char Sr[11],Sq[11];
6 int Year,Time,My,Mt,Md,Dy,Dt,i,M[] = {1,31,2,28,3,31,4,30,5,31,6,30,7,31,8,31,9,30,10,31,11,30,12,31};
7
8 printf("请输入您的生日(如1988-05-20):");
9 scanf("%s",Sr);
10 printf("请输入当前日期(如2019-03-31):");
11 scanf("%s",Sq);
12
13 Year = (Sr[0]-'0')*1000+(Sr[1]-'0')*100+(Sr[2]-'0')*10+Sr[3]-'0';
14 My = (Sr[5]-'0')*10+Sr[6]-'0';
15 Dy = (Sr[8]-'0')*10+Sr[9]-'0';
16 Time = (Sq[0]-'0')*1000+(Sq[1]-'0')*100+(Sq[2]-'0')*10+Sq[3]-'0';
17 Mt = (Sq[5]-'0')*10+Sq[6]-'0';
18 Dt = (Sq[8]-'0')*10+Sq[9]-'0';
19
20 for (;Year <= Time ; Year++)
21 {
22 if ( (Year % 4 == 0 && Year % 100 != 0 ) || Year % 400 == 0 )
23 {
24 for ( i = 0 ; i < 24 ; i+=2 )
25 {
26 if ( i == 2)
27 {
28 Md = Md + M[i+1]+1;
29 }
30 Md = Md + M[i+1];
31 }
32 }
33 else
34 {
35 for ( i = 0 ; i < 24 ; i+=2 )
36 {
37 Md = Md + M[i+1];
38 }
39 }
40 }
41
42 printf("你在这个世界上总共生存了%d天%d\n",Year,Time);
43 printf("Sr0=%d Sq0=%c\n",Sr[0],Sq[0]);
44 printf("Sr1=%c Sq1=%c\n",Sr[1],Sq[1]);
45 printf("Sr2=%c Sq2=%c\n",Sr[2],Sq[2]);
46 printf("Sr3=%c Sq3=%c\n",Sr[3],Sq[3]);
47 printf("Sr4=%c Sq4=%c\n",Sr[4],Sq[4]);
48 printf("Sr5=%c Sq5=%c\n",Sr[5],Sq[5]);
49 printf("Sr6=%c Sq6=%c\n",Sr[6],Sq[6]);
50 printf("Sr7=%c Sq7=%c\n",Sr[7],Sq[7]);
51 printf("Sr8=%c Sq8=%c\n",Sr[8],Sq[8]);
52 printf("Sr9=%c Sq9=%c\n",Sr[9],Sq[9]);
53 printf("Sr10=%c Sq10=%c\n",Sr[10],Sq[10]);
54 printf("Sr11=%c Sq11=%c\n",Sr[11],Sq[11]);
55 printf("Sr=%p Sq=%p\n",Sr,Sq);
56 printf("Sr[0]=%p Sq[0]=%p\n",Sr+0,Sq+0);
57 printf("Sr[1]=%p Sq[1]=%p\n",Sr+1,Sq+1);
58 printf("Sr[2]=%p Sq[2]=%p\n",Sr+2,Sq+2);
59 printf("Sr[3]=%p Sq[3]=%p\n",Sr+3,Sq+3);
60
61 return 0;
62 }
以上代码,为什么Year的值不正确??高手帮忙下拉,只要修改Time = (Sq[0]-'0')*1000+(Sq[1]-'0')*100+(Sq[2]-'0')*10+Sq[3]-'0';为Time = (Sq[1]-'0')*1000+(Sq[1]-'0')*100+(Sq[2]-'0')*10+Sq[3]-'0';
Year的值就正确了,但Time又出错,输出数组中的每位数均未发现异常,数据正确。
|
|