Lập trình c

ngovannghi

New member
chào cả nhà.có ai học C ko thì vào đây cùng trao đổi!

đây là đoạn code đơn giản in ra màn hình lịch của một năm.




#include <stdio.h>
#include <math.h>
int week(int ngay,int thang,int nam)

{
int thu;
int i;
long songay=0;

for(i=1;i<=nam-1;i++)
{
if((i%400==0)||((i%4==0)&&(i%100!=0)))
{songay=songay+366;}

else
{
songay=songay+365;
}
songay=songay;
}
for(i=1;i<=thang-1;i++)
{
if((nam%400==0)||((nam%4==0)&&(nam%100!=0)))
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
{
songay=songay+31;
}

else if(i==2)
{
songay=songay+29;
}

else
{
songay=songay+30;
}
songay=songay;
}
else
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
{
songay=songay+31;
}

else if(i==2)
{
songay=songay+28;
}

else
{
songay=songay+30;
}
songay=songay;
}songay=songay;
}
songay=songay+ngay;
switch(songay%7)
{
case 0:
thu=8;
break;
case 1:
thu=2;
break;
case 2:
thu=3;
break;
case 3:
thu=4;
break;
case 4:
thu=5;
break;
case 5:
thu=6;
break;
case 6:
thu=7;

break;
}
return thu;
}

main()
{
int j,thang,nam,ngay,t;
printf("hay nhap thang va nam:\n");
scanf("%d-%d",&thang,&nam);
if(thang==2)
{
if((nam%400==0)||(nam%4==0&&nam%100!=0))
ngay=29;
else
ngay=28;
}
else if(thang==1||thang==3||thang==5||thang==7||thang==8||thang==10||thang==12)
ngay=31;
else
ngay=30;
printf("THANG %d - NAM %d\n\n\n\n",thang,nam);
printf(" T2 T3 T4 T5 T6 T7 CN\n\n");

if(week(1,thang,nam)==2)
{j=1;t=1;
printf("%10d",j);
for(j=2;j<=ngay;j++)
{t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");

}
}
else if(week(1,thang,nam)==3)
{j=1;t=2;
printf("%20d",j);
for(j=2;j<=ngay;j++)
{t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");

}
}
else if(week(1,thang,nam)==4)
{j=1;t=3;
printf("%30d",j);
for(j=2;j<=ngay;j++)
{t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");

}}
else if(week(1,thang,nam)==5)
{
j=1;t=4;
printf("%40d",j);
for(j=2;j<=ngay;j++)
{t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");

}}
else if(week(1,thang,nam)==6)
{
j=1;t=5;
printf("%50d",j);
for(j=2;j<=ngay;j++)
{t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");

}
}
else if(week(1,thang,nam)==7)
{
j=1;t=6;
printf("%60d",j);
for(j=2;j<=ngay;j++)
{t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");}
}
else
{t=1;
printf("%70d\n",j);
for(j=2;j<=ngay;j++)
{
t++;
printf("%10d",j);
if(t%7==0)
printf("\n\n\n");


}
}
printf("\n");


}

:banhbao48::banhbao48:
 

duckhai_hp

New member
cai nay thi de lam j dau neu ban co tai lieu thi post len thay tot hon do co c# nua thi cang tot

ai pro ve lap trinh giao tiep vdk voi may tinh bang c# thi chi minh voi nhe!
 
Top