PHP:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#ifndef PI
#define PI 3.14159265358979323846
#endif
char ho[20], tenlot[20], ten[10], sho[20], stenlot[20], sten[10];
int S_dd,S_mm,S_yy;//ngay duong lich
void xemtentrunghoa(int dd,int mm,int yyyy);
int dudoangioitinh(char tenlot[20]);
int cungtuvi(int dd, int mm);
int vanmang(int dd, int mm);
int ynghiaten(char ten[10]);
int ynghiaten(char ten[10]);
void gioithieu(int n);
int validSolar(int dd,int mm,int yy);//check ngay duong hop le
int Solar2JD(int dd,int mm,int yy);//chuyen duong lich ve So ngay Julius
int getNewMoonDay(int k, int timeZone);//tinh ngay soc thu k ke tu ngay 1/1/1900, tra ve ngay JD.
int getSunLongitude(int jdn,int timeZone);
int getLunarMonth11(int yy,int timeZone);
int getLeapMonthOffset(int a11,int timeZone);
int inlicham(int S_dd,int S_mm,int S_yy);
/*Phan than chuong trinh*/
int main()
{
clrscr;
int dd, mm, yyyy;
int chon;
printf("Moi ban nhap Ho: ");
fflush(stdin);
gets(ho);
printf("Moi ban nhap ten lot: ");
fflush(stdin);
gets(tenlot);
printf("Moi ban nhap ten: ");
fflush(stdin);
gets(ten);
printf("Ngay sinh: ");
scanf("%d",&dd);
printf("Thang sinh: ");
scanf("%d",&mm);
printf("Nam sinh: ");
scanf("%d",&yyyy);
printf("Ban ten: %s %s %s",strupr(ho), strupr(tenlot), strupr(ten));
printf("\nSinh ngay: %d/%d/%d",dd, mm, yyyy);
strcpy(sten,strlwr(ten));
strcpy(stenlot,strlwr(tenlot));
strcpy(sho,strlwr(ho));
while(1)
{
clrscr;
printf("\n\n\n\t\t\t CHUONG TRINH XEM TU VI");
printf("\n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\t* *");
printf("\n\t* 1. Xem Ten Trung Hoa. *");
printf("\n\t* 2. Y nghia cua Ten. *");
printf("\n\t* 3. Du doan gioi tinh. *");
printf("\n\t* 4. Xem cung Tu Vi. *");
printf("\n\t* 5. Xem van mang. *");
printf("\n\t* 6. Xem am lich. *");
printf("\n\t* 7. Gioi thieu. *");
printf("\n\t* 8. Exit. *");
printf("\n\t* *");
printf("\n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\t* Designer: Truong Dinh Hung *");
printf("\n\t* Class: DCT1091 *");
printf("\n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\n\n\tVui Long Nhan Phim De Lua Chon Cac Chuc Nang Tuong Ung : ");
scanf("%d",&chon);
switch(chon)
{
case 1:
clrscr;
printf("\nTen Trung Hoa cua ban la: ");
xemtentrunghoa(dd,mm,yyyy);
break;
case 2:
clrscr;
ynghiaten(ten);
break;
case 3:
clrscr;
printf("\nUmbal...xi...bua! Ban thuoc phai: ");
if(dudoangioitinh(tenlot)==1) printf("Nu");
else printf("Nam");
break;
case 4:
clrscr;
cungtuvi(dd,mm);
break;
case 5:
clrscr;
vanmang(dd,mm);
break;
case 6:
clrscr;
inlicham(S_dd,S_mm,S_yy);
break;
case 7:
clrscr;
gioithieu(1);
break;
default : return 0;
}
}
getch();
}
/***Hàm xem tên Trung Hoa c?a b?n***/
void xemtentrunghoa(int dd,int mm,int yyyy)
{
clrscr;
switch(yyyy % 10)
{
case 0:
printf("%s","Lie^~u ");
break;
case 1:
printf("%s","Duo`ng ");
break;
case 2:
printf("%s","Nhan ");
break;
case 3:
printf("%s","Au Duong ");
break;
case 4:
printf("%s","Diep ");
break;
case 5:
printf("%s","Dong Phuong ");
break;
case 6:
printf("%s","Do^~ ");
break;
case 7:
printf("%s","Lang ");
break;
case 8:
printf("%s","Hoa ");
break;
case 9:
printf("%s","Ma.c ");
break;
}
switch(mm)
{
case 1:
printf("%s","Lam ");
break;
case 2:
printf("%s","Thie^n ");
break;
case 3:
printf("%s","Bi'ch ");
break;
case 4:
printf("%s","Vo^ ");
break;
case 5:
printf("%s","Song ");
break;
case 6:
printf("%s","Nga^n ");
break;
case 7:
printf("%s","Ngo.c ");
break;
case 8:
printf("%s","Ky` ");
break;
case 9:
printf("%s","Truc ");
break;
case 10:
printf("%s","");
break;
case 11:
printf("%s","Y ");
break;
case 12:
printf("%s","Nhuo.c ");
break;
}
switch(dd)
{
case 1:
printf("%s","Lam ");
break;
case 2:
printf("%s","Nguye^.t ");
break;
case 3:
printf("%s","Tuye^'t ");
break;
case 4:
printf("%s","Tha^`n ");
break;
case 5:
printf("%s","Ninh ");
break;
case 6:
printf("%s","Bi`nh ");
break;
case 7:
printf("%s","La.c ");
break;
case 8:
printf("%s","Doanh ");
break;
case 9:
printf("%s","Thu ");
break;
case 10:
printf("%s","Khue^ ");
break;
case 11:
printf("%s","Ca ");
break;
case 12:
printf("%s","Thie^n ");
break;
case 13:
printf("%s","Ta^m ");
break;
case 14:
printf("%s","Ha`n ");
break;
case 15:
printf("%s","Y ");
break;
case 16:
printf("%s","Die^~m ");
break;
case 17:
printf("%s","Song ");
break;
case 18:
printf("%s","Dung ");
break;
case 19:
printf("%s","Nhu");
break;
case 20:
printf("%s","Hue^. ");
break;
case 21:
printf( "%s","Di`nh ");
break;
case 22:
printf("%s","Giai ");
break;
case 23:
printf("%s","Phong ");
break;
case 24:
printf( "%s","Tuye^n ");
break;
case 25:
printf("%s","Tu ");
break;
case 26:
printf("%s","Vi ");
break;
case 27:
printf("%s","Nhi ");
break;
case 28:
printf("%s","Va^n ");
break;
case 29:
printf("%s","Giang ");
break;
case 30:
printf("%s","Phi ");
break;
case 31:
printf("%s","Phu'c ");
break;
}
getch();
}
int dudoangioitinh(char tenlot[20])
{
clrscr;
int ok=0;
if(strcmp("thi",strlwr(tenlot))==0) ok=1;
if(strcmp("uyen",strlwr(tenlot))==0) ok=1;
if(strcmp("bich",strlwr(tenlot))==0) ok=1;
if(strcmp("nhu",strlwr(tenlot))==0) ok=1;
if(strcmp("thuy",strlwr(tenlot))==0) ok=1;
if(strcmp("ngoc",strlwr(tenlot))==0) ok=1;
return ok;
}
int cungtuvi(int dd, int mm)
{
clrscr;
char c[1000000];
int i=0,j;
FILE *pFile;
if(((mm==1)&&(dd>=20))||((mm==2)&&(dd<=18)))
{
pFile = fopen ("cungbaobinh.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Bao Binh...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==2)&&(dd>=19))||((mm==3)&&(dd<=20)))
{
pFile = fopen ("cungsongngu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Song Ngu...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==3)&&(dd>=21))||((mm==4)&&(dd<=19)))
{
pFile = fopen ("cungmienduong.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Mien Duong...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==4)&&(dd>=20))||((mm==5)&&(dd<=20)))
{
pFile = fopen ("cungkimnguu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Kim Nguu...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==5)&&(dd>=21))||((mm==6)&&(dd<=20)))
{
pFile = fopen ("cungsongnam.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Song Nam...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==6)&&(dd>=21))||((mm==7)&&(dd<=22)))
{
pFile = fopen ("cungbacgiai.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Bac Giai...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==7)&&(dd>=23))||((mm==8)&&(dd<=22)))
{
pFile = fopen ("cunghaisu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Hai Su...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==8)&&(dd>=23))||((mm==9)&&(dd<=22)))
{
pFile = fopen ("cungsunu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Su Nu...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==9)&&(dd>=23))||((mm==10)&&(dd<=23)))
{
pFile = fopen ("cungthienxung.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Thien Xung...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==10)&&(dd>=24))||((mm==11)&&(dd<=21)))
{
pFile = fopen ("cunghocap.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Ho Cap...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==11)&&(dd>=22))||((mm==12)&&(dd<=21)))
{
pFile = fopen ("cungnhanma.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Nhan Ma...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==12)&&(dd>=22))||((mm==1)&&(dd<=19)))
{
pFile = fopen ("cungnamduong.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Nam Duong...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
}
int vanmang(int dd, int mm)
{
clrscr;
char c[1000000];
int i=0,j;
FILE *pFile;
if(((mm==1)&&(dd>=20))||((mm==2)&&(dd<=18)))
{
pFile = fopen ("vanmangbaobinh.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Bao Binh...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==2)&&(dd>=19))||((mm==3)&&(dd<=20)))
{
pFile = fopen ("vanmangsongngu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Song Ngu...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==3)&&(dd>=21))||((mm==4)&&(dd<=19)))
{
pFile = fopen ("vanmangmienduong.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Mien Duong...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==4)&&(dd>=20))||((mm==5)&&(dd<=20)))
{
pFile = fopen ("vanmangkimnguu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Kim Nguu...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==5)&&(dd>=21))||((mm==6)&&(dd<=20)))
{
pFile = fopen ("vanmangsongnam.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Song Nam...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==6)&&(dd>=21))||((mm==7)&&(dd<=22)))
{
pFile = fopen ("vanmangbacgiai.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Bac Giai...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==7)&&(dd>=23))||((mm==8)&&(dd<=22)))
{
pFile = fopen ("vanmanghaisu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Hai Su...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==8)&&(dd>=23))||((mm==9)&&(dd<=22)))
{
pFile = fopen ("vanmangsunu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Su Nu...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==9)&&(dd>=23))||((mm==10)&&(dd<=23)))
{
pFile = fopen ("vanmangthienxung.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Thien Xung...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==10)&&(dd>=24))||((mm==11)&&(dd<=21)))
{
pFile = fopen ("vanmanghocap.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Ho Cap...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==11)&&(dd>=22))||((mm==12)&&(dd<=21)))
{
pFile = fopen ("vanmangnhanma.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Nhan Ma...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if(((mm==12)&&(dd>=22))||((mm==1)&&(dd<=19)))
{
pFile = fopen ("vanmangnamduong.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nBan thuoc cung Nam Duong...\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
}
int ynghiaten(char ten[10])
{
clrscr;
char c[1000000];
strcpy(sten,strlwr(ten));
int i=0,j;
FILE *pFile;
if (sten[0]=='a')
{
pFile = fopen ("tenvana.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='b')
{
pFile = fopen ("tenvanb.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='c')
{
pFile = fopen ("tenvanc.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='d')
{
pFile = fopen ("tenvand.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='e')
{
pFile = fopen ("tenvane.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='g')
{
pFile = fopen ("tenvang.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='h')
{
pFile = fopen ("tenvanh.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='k')
{
pFile = fopen ("tenvank.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='l')
{
pFile = fopen ("tenvanl.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='m')
{
pFile = fopen ("tenvanm.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='n')
{
pFile = fopen ("tenvann.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='o')
{
pFile = fopen ("tenvano.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='p')
{
pFile = fopen ("tenvanp.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='q')
{
pFile = fopen ("tenvanq.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='r')
{
pFile = fopen ("tenvanr.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='s')
{
pFile = fopen ("tenvans.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='t')
{
pFile = fopen ("tenvant.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='u')
{
pFile = fopen ("tenvanu.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='v')
{
pFile = fopen ("tenvan.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='x')
{
pFile = fopen ("tenvanx.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
else if (sten[0]=='y')
{
pFile = fopen ("tenvany.txt","r");
if(pFile==NULL)
{
printf("\nKhong the mo file\n");
}
else printf("\nY nghia ten cua ban la:\n");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
return 0;
}
}
void gioithieu(int n)
{
char c[1000000];
int i=0,j;
FILE *pFile;
pFile = fopen ("gioithieu1.txt","r");
while (!feof(pFile))
{
fscanf(pFile,"%c",&c[i]);
i++;
}
fclose(pFile);
for(j=0;j<i-1;j++)
printf("%c",c[j]);
getch();
}
int validSolar(int dd,int mm,int yy){//check ngay duong hop le
if (dd < 1 || dd > 32 || mm < 1 || mm > 12)
return 0;
if ( mm == 2){
if ( yy % 400 == 0)
return (dd < 30);
if ( yy % 100 == 0)
return (dd < 29);
if ( yy % 4 == 0)
return (dd<30);
return (dd < 29);
}
if ( mm == 4 || mm == 6 || mm == 9 || mm == 11)
return (dd < 31);
return 1;
}
int Solar2JD(int dd,int mm,int yy){//chuyen duong lich ve So ngay Julius
int a,y,m,JD;
a = (14 - mm) / 12;
y = yy+4800-a;
m = mm+12*a-3;
JD = dd + (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045;// After 5/10/1582, Gregorian calendar
if(JD < 2299161)// After 5/10/1582, Julius calendar
JD = dd + (153*m+2)/5 + 365*y + y/4 - 32083;
return JD;
}
int getNewMoonDay(int k, int timeZone){//tinh ngay soc thu k ke tu ngay 1/1/1900, tra ve ngay JD.
double T, T2, T3, dr, Jd1, M, Mpr, F, C1, deltat, JdNew;
T = k/1236.85; // Time in Julian centuries from 1900 January 0.5
T2 = T * T;
T3 = T2 * T;
dr = PI/180;
Jd1 = 2415020.75933 + 29.53058868*k + 0.0001178*T2 - 0.000000155*T3;
Jd1 = Jd1 + 0.00033*sin((166.56 + 132.87*T - 0.009173*T2)*dr); // Mean new moon
M = 359.2242 + 29.10535608*k - 0.0000333*T2 - 0.00000347*T3; // Sun's mean anomaly
Mpr = 306.0253 + 385.81691806*k + 0.0107306*T2 + 0.00001236*T3; // Moon's mean anomaly
F = 21.2964 + 390.67050646*k - 0.0016528*T2 - 0.00000239*T3; // Moon's argument of latitude
C1=(0.1734 - 0.000393*T)*sin(M*dr) + 0.0021*sin(2*dr*M);
C1 = C1 - 0.4068*sin(Mpr*dr) + 0.0161*sin(dr*2*Mpr);
C1 = C1 - 0.0004*sin(dr*3*Mpr);
C1 = C1 + 0.0104*sin(dr*2*F) - 0.0051*sin(dr*(M+Mpr));
C1 = C1 - 0.0074*sin(dr*(M-Mpr)) + 0.0004*sin(dr*(2*F+M));
C1 = C1 - 0.0004*sin(dr*(2*F-M)) - 0.0006*sin(dr*(2*F+Mpr));
C1 = C1 + 0.0010*sin(dr*(2*F-Mpr)) + 0.0005*sin(dr*(2*Mpr+M));
if (T < -11) {
deltat= 0.001 + 0.000839*T + 0.0002261*T2 - 0.00000845*T3 - 0.000000081*T*T3;
} else {
deltat= -0.000278 + 0.000265*T + 0.000262*T2;
}
JdNew = Jd1 + C1 - deltat;
return (JdNew + 0.5 + timeZone/24);
}
int getSunLongitude(int jdn,int timeZone){
double T, T2, dr, M, L0, DL, L;
T = (jdn - 2451545.5 - timeZone/24) / 36525; // Time in Julian centuries from 2000-01-01 12:00:00 GMT
T2 = T*T;
dr = PI/180; // degree to radian
M = 357.52910 + 35999.05030*T - 0.0001559*T2 - 0.00000048*T*T2; // mean anomaly, degree
L0 = 280.46645 + 36000.76983*T + 0.0003032*T2; // mean longitude, degree
DL = (1.914600 - 0.004817*T - 0.000014*T2)*sin(dr*M);
DL = DL + (0.019993 - 0.000101*T)*sin(dr*2*M) + 0.000290*sin(dr*3*M);
L = L0 + DL; // true longitude, degree
L = L*dr;
L = L - (PI*2*((int)(L/(PI*2)))); // Normalize to (0, 2*PI)
L /= (PI * 6);
return L;
}
int getLunarMonth11(int yy,int timeZone){
int k, off, nm, sunLong;
off = Solar2JD(31, 12, yy) - 2415021;
k = (int)(off / 29.530588853);
nm = getNewMoonDay(k, timeZone);
sunLong = getSunLongitude(nm, timeZone); // sun longitude at local midnight
if (sunLong >= 9) {
nm = getNewMoonDay(k-1, timeZone);
}
return nm;//tra ve ngay dau thang 11 am lich theo so ngay Julius day
}
int getLeapMonthOffset(int a11,int timeZone){
int k, last, arc, i;
k = (int)((a11 - 2415021.076998695) / 29.530588853 + 0.5);
last = 0;
i = 1; // We start with the month following lunar month 11
arc = getSunLongitude(getNewMoonDay(k+i, timeZone), timeZone);
do {
last = arc;
i++;
arc = getSunLongitude(getNewMoonDay(k+i, timeZone), timeZone);
} while (arc != last && i < 14);
return i-1;
}
int inlicham(int S_dd, int S_mm,int S_yy)
{
printf("\nMoi ban nhap ngay/thang/nam Duong lich (roi nhan Enter): ");
scanf("%d/%d/%d",&S_dd,&S_mm,&S_yy);
if(validSolar(S_dd,S_mm,S_yy)){
int L_dd,L_mm,L_yy;//ngay thang nam am bang so
char dCan[5], mCan[5], yCan[5];//Can cua ngay thang nam am
//Giap, At, Binh, Dinh, Mau, Ky, Canh, Tan, Nham, Quy
char dChi[5], mChi[5], yChi[5];//Chi cua ngay thang nam am lich
//Ty, Suu, Dan, Meo, Thin, Ty, Ngo, Mui, Than, Dau, Tuat, Hoi
int L_nhuan;//nhuan==0 thuong, nhuan==1 nhuan
char LNhuan[8]="";
int JD;//Julius date
int k, monthStart, a11, b11,diff;
//int timeZone = 7;
JD = Solar2JD(S_dd,S_mm,S_yy);
k = ((JD - 2415021.076998695) / 29.530588853);
monthStart = getNewMoonDay(k+1, 7);//Theo mui gio o Viet Nam la 7
if (monthStart > JD) {
monthStart = getNewMoonDay(k, 7);//Theo mui gio o Viet Nam la 7
}
a11 = getLunarMonth11(S_yy, 7);//Theo mui gio o Viet Nam la 7
b11 = a11;
if (a11 >= monthStart) {
L_yy = S_yy;
a11 = getLunarMonth11(S_yy-1, 7);//Theo mui gio o Viet Nam la 7
} else {
L_yy = S_yy+1;
b11 = getLunarMonth11(S_yy+1, 7);//Theo mui gio o Viet Nam la 7
}
L_dd = JD-monthStart+1;
diff =
((monthStart - a11)/29);
L_nhuan = 0;
L_mm = diff+11;
if (b11 - a11 > 365) {
int leapMonthDiff = getLeapMonthOffset(a11, 7);//Theo mui gio o Viet Nam la 7
if (diff >= leapMonthDiff) {
L_mm = diff + 10;
if (diff == leapMonthDiff) {
L_nhuan = 1;
}
}
}
if (L_mm > 12) {
L_mm -= 12;
}
if (L_mm >= 11 && diff < 4) {
L_yy -= 1;
}
//Xac dinh Can va Chi cho Am lich
//Can cua nam
switch((L_yy+6)%10){//Giap, At, Binh, Dinh, Mau, Ky, Canh, Tan, Nham, Quy
case 0: strcpy(yCan,"Giap");
break;
case 1: strcpy(yCan,"At");
break;
case 2: strcpy(yCan,"Binh");
break;
case 3: strcpy(yCan,"Dinh");
break;
case 4: strcpy(yCan,"Mau");
break;
case 5: strcpy(yCan,"Ky");
break;
case 6: strcpy(yCan,"Canh");
break;
case 7: strcpy(yCan,"Tan");
break;
case 8: strcpy(yCan,"Nham");
break;
default: strcpy(yCan,"Quy");
}
//Chi cua nam
switch((L_yy+7)%12){
case 0: strcpy(yChi,"Suu");
break;
case 1: strcpy(yChi,"Da`n");
break;
case 2: strcpy(yChi,"Ma~o");
break;
case 3: strcpy(yChi,"Thin");
break;
case 4: strcpy(yChi,"Ty.");
break;
case 5: strcpy(yChi,"Ngo.");
break;
case 6: strcpy(yChi,"Mu`i");
break;
case 7: strcpy(yChi,"Than");
break;
case 8: strcpy(yChi,"Da.u");
break;
case 9: strcpy(yChi,"Tuat");
break;
case 10: strcpy(yChi,"Ho.i");
break;
default: strcpy(yChi,"Ti\'");
}
//Can cua thang
switch((L_yy*12+L_mm+3)%10){
case 0: strcpy(mCan,"Giap");
break;
case 1: strcpy(mCan,"At");
break;
case 2: strcpy(mCan,"Binh");
break;
case 3: strcpy(mCan,"Dinh");
break;
case 4: strcpy(mCan,"Mau");
break;
case 5: strcpy(mCan,"Ky");
break;
case 6: strcpy(mCan,"Canh");
break;
case 7: strcpy(mCan,"Tan");
break;
case 8: strcpy(mCan,"Nham");
break;
default: strcpy(mCan,"Quy");
}
//Chi cua thang
switch(L_mm){
case 1: strcpy(mChi,"Da`n");
break;
case 2: strcpy(mChi,"Ma~o");
break;
case 3: strcpy(mChi,"Thin");
break;
case 4: strcpy(mChi,"Ty.");
break;
case 5: strcpy(mChi,"Ngo.");
break;
case 6: strcpy(mChi,"Mu`i");
break;
case 7: strcpy(mChi,"Than");
break;
case 8: strcpy(mChi,"Da.u");
break;
case 9: strcpy(mChi,"Tuat");
break;
case 10: strcpy(mChi,"Ho.i");
break;
case 11: strcpy(mChi,"Ti\'");
break;
case 12: strcpy(mChi,"Suu");
}
//Can cua ngay
switch((JD+9)%10){
case 0: strcpy(dCan,"Giap");
break;
case 1: strcpy(dCan,"At");
break;
case 2: strcpy(dCan,"Binh");
break;
case 3: strcpy(dCan,"Dinh");
break;
case 4: strcpy(dCan,"Mau");
break;
case 5: strcpy(dCan,"Ky");
break;
case 6: strcpy(dCan,"Canh");
break;
case 7: strcpy(dCan,"Tan");
break;
case 8: strcpy(dCan,"Nham");
break;
default: strcpy(dCan,"Quy");
}
//Chi cua ngay
switch(JD%12){
case 0: strcpy(dChi,"Suu");
break;
case 1: strcpy(dChi,"Da`n");
break;
case 2: strcpy(dChi,"Ma~o");
break;
case 3: strcpy(dChi,"Thin");
break;
case 4: strcpy(dChi,"Ty.");
break;
case 5: strcpy(dChi,"Ngo.");
break;
case 6: strcpy(dChi,"Mu`i");
break;
case 7: strcpy(dChi,"Than");
break;
case 8: strcpy(dChi,"Da.u");
break;
case 9: strcpy(dChi,"Tuat");
break;
case 10: strcpy(dChi,"Ho.i");
break;
default: strcpy(dChi,"Ti\'");
}
if(L_nhuan)
strcpy(LNhuan," nhuan");
printf("...........................................................................");
printf("\nNgay sinh: %d/%d/%d \n\tLa Ngay %d, thang %d%s, nam %d ",S_dd,S_mm,S_yy,L_dd,L_mm,LNhuan,L_yy);
printf("Am lich theo Lich Viet Nam\nHoac\nNgay %s %s, thang %s %s%s, nam %s %s\n",dCan,dChi,mCan,mChi,LNhuan,yCan,yChi);
}
else
printf("Error Input");
getch();
return 0;
}
Các bạn download file này nữa nhe: