codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
// Codepad 에서 sin() 을 인식못함... 그래서 실행은 안 걸어둠 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #define BIORHYTHM_PI 3.141592 #define ROUND_DOUBLE(x) ((x > 0.0) ? floor(x+.5) : ceil(x-.5)) enum { PHYSICAL, EMOTIONAL, INTELLECTUAL }; #define PHYSICAL_CYCLE_DAYS (23) #define EMOTIONAL_CYCLE_DAYS (28) #define INTELLECTUAL_CYCLE_DAYS (33) //double round(double x); int getBiorhythm(int days, int mode); int get_age_in_days(int year, int month, int day); int main(void) { int days; days = get_age_in_days(1984, 3, 2); printf("%d days - phy : %d, emo : %d, int : %d\n", days, getBiorhythm(days, PHYSICAL), getBiorhythm(days, EMOTIONAL), getBiorhythm(days, INTELLECTUAL) ); return 0; } /* double round(double x) { return ((x>0) ? floor(x+.5) : ceil(x-.5)); } */ int getBiorhythm(int days, int mode) { int cycle = 0; switch(mode) { case PHYSICAL: cycle = PHYSICAL_CYCLE_DAYS; break; case EMOTIONAL: cycle = EMOTIONAL_CYCLE_DAYS; break; case INTELLECTUAL: cycle = INTELLECTUAL_CYCLE_DAYS; break; default: cycle = 0; } return (int)(ROUND_DOUBLE(sin(days * 2 * BIORHYTHM_PI / cycle) * 100.0)); //return (int)(round(sin(days * 2 * BIORHYTHM_PI / cycle) * 100.0)); } int get_age_in_days(int year, int month, int day) { struct tm * local_tm, birth_tm; time_t current_t, birth_t; double diff_sec; birth_tm.tm_sec = 0; birth_tm.tm_min = 0; birth_tm.tm_hour = 0; birth_tm.tm_mday = day; birth_tm.tm_mon = month - 1; // Month - 1 birth_tm.tm_year = year - 1900; // from 1900 birth_tm.tm_isdst = -1; birth_t = mktime(&birth_tm); time(¤t_t); local_tm = localtime(¤t_t); diff_sec = difftime(current_t, birth_t); // 1 days = 24 * 60 * 60 // then floor return (int)(diff_sec / (24 * 60 * 60)); }
Private
[
?
]
Run code