Created
May 17, 2012 18:42
-
-
Save desg/2720830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main() | |
{ | |
time_t now = time(0); | |
struct tm* tm = localtime(&now); | |
int date[3] = {tm->tm_mon, tm->tm_mday, tm->tm_year}; | |
//printf("%d\n", date[2]); | |
// following the gregorian to julian day | |
int a = (14-(date[0]+1))/12; | |
int y = (date[2]+1900) + 4800 - a; | |
int m = date[0] + 12*a -3; | |
int JDN = date[1] + ((153*m + 2)/5) + 365*y + (y/4) - (y/100) + (y/400) - 32045; | |
int phase = (JDN - 2451550)%29; | |
//going to determine the phase of the moon | |
if(phase < 2) | |
{ | |
printf("New Moon\n"); | |
} | |
else if(phase < 6 ) | |
{ | |
printf("Waxing Crescent\n"); | |
} | |
else if(phase < 13) | |
{ | |
printf("First Quarter\n"); | |
} | |
else if(phase < 17) | |
{ | |
printf("Full\n" ); | |
} | |
else if (phase < 20) | |
{ | |
printf("Waning Gibbous\n"); | |
} | |
else if(phase < 23) | |
{ | |
printf("Last Quarter\n" ); | |
} | |
else if (phase < 28) | |
{ | |
printf("Waning Crescent\n" ); | |
} | |
else | |
{ | |
printf("New Moon\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment