Palendromic Numbers
// Given a palendromic start date 2001/10/02
// calculate the next 10 future date palendromes.
#include "stdafx.h"
#include<conio.h>
#define STRINGLENGTH 19
long jd(int y, int m, int d);
void gd (long JD, int *y, int *m, int *d);
int IsPallendrome (char Date[]);
void main()
{
int Year, Month, Day, count;
long Julian;
Year = 2001;
Month = 10;
Day = 02;
char d[20];
count = 1;
Julian = jd(Year, Month, Day); // Seed the start date with the Julian date
for(;;)
{
gd(Julian,&Year, &Month, &Day); // convert Julian to Gregorian
sprintf_s(d,"%4d%02d%02d\n", Year, Month, Day); // make date string
if(IsPallendrome(d)) // test for palendromw
{
printf(" %d: %s is a Palendrome\n",count,d); // yay we found one
count += 1;
if (count > 10) break; // found enough?
}
Julian += 1; // bump julian and look more
}
_getch();
}
//Gregorian to Julian
long jd(int y, int m, int d)
{
y+=8000;
if(m<3) { y--; m+=12; }
return (y*365) +(y/4) -(y/100) +(y/400) -1200820
+(m*153+3)/5-92
+d-1;
}
// Julian to Gregorian
void gd (long JD, int *y, int *m, int *d)
{
int I,J,K,L,N;
L = JD + 68569;
N = 4*L/146097;
L = L-(146097*N+3)/4;
I = 4000*(L+1)/1461001;
L = L-1461*I/4+31;
J = 80*L/2447;
K = L-2447*J/80;
L = J/11;
J = J+2-12*L;
I = 100*(N-49)+I+L;
*y = I;
*m = J;
*d = K;
}
// is it a palendrome
int IsPallendrome (char Date[])
{
int y = 7;
for (int x = 0; x < 4; ++x, --y)
{
if (Date[x] != Date[y])
return(false);
}
return(true);
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
jnawrocki -3 Light Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
jnawrocki -3 Light Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
jnawrocki -3 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.