LaoLiulaoliu
December 8th, 2006, 11:52 AM
I have wrote a c program,it is used for print date(from 20030101 to 20041231).
There is some bugs in my program,but I can not find it.
May be I need some help.Thanks for the people helping me!
The bug is different months show the mess day-count(june have 29 days,other months is the same)
The program as follows:
#include<stdio.h>
main()
{
int d[2]={0,1},m[2]={0,1},y[4]={2,0,0,3};
int year,month,day;
while(y[3]<5){
year=y[0]*1000+y[1]*100+y[2]*10+y[3];
month=1;
m[0]=0;m[1]=1;
while(month<12) {
month=m[0]*10+m[1];
d[0]=0;d[1]=1;
while(1) {
day=d[0]*10+d[1];
printf("%d%d%d%d%d%d%d%d\n",y[0],y[1],y[2],y[3],m[0],m[1],d[0],d[1]);
if(d[1]==9)
{d[1]=0;
d[0]++;}
else d[1]++;
if(month==1||3||5||7||8||10||12){
if(day==31) break;
}
if(month==4||6||9||11){
if(day==30) break;
}
if((year%4==0&&year%100!=0)||(year%400==0))
{if(day==29)break;}
else
if(day==28 )break;
}
if(m[1]==9)
{m[1]=0;
m[0]++;}
else m[1]++;
}
if(y[3]==9)
{y[3]=0;
y[2]++;}
else y[3]++;
}
}
There is some bugs in my program,but I can not find it.
May be I need some help.Thanks for the people helping me!
The bug is different months show the mess day-count(june have 29 days,other months is the same)
The program as follows:
#include<stdio.h>
main()
{
int d[2]={0,1},m[2]={0,1},y[4]={2,0,0,3};
int year,month,day;
while(y[3]<5){
year=y[0]*1000+y[1]*100+y[2]*10+y[3];
month=1;
m[0]=0;m[1]=1;
while(month<12) {
month=m[0]*10+m[1];
d[0]=0;d[1]=1;
while(1) {
day=d[0]*10+d[1];
printf("%d%d%d%d%d%d%d%d\n",y[0],y[1],y[2],y[3],m[0],m[1],d[0],d[1]);
if(d[1]==9)
{d[1]=0;
d[0]++;}
else d[1]++;
if(month==1||3||5||7||8||10||12){
if(day==31) break;
}
if(month==4||6||9||11){
if(day==30) break;
}
if((year%4==0&&year%100!=0)||(year%400==0))
{if(day==29)break;}
else
if(day==28 )break;
}
if(m[1]==9)
{m[1]=0;
m[0]++;}
else m[1]++;
}
if(y[3]==9)
{y[3]=0;
y[2]++;}
else y[3]++;
}
}