girilen tarihten bir sonraki tarihi ve günü veren program
Kod:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Variables of Computing The Day of Month
int day, month, year;
int isLeap, isValid, l_d_o_feb = 29;//l_d_o_feb: last day of february
char choice='y';
int mod4, mod100, mod400;
int flag=0; //for control of 1900-2099 years
//Variables of Computing The Day of The Week
int val_cents;
int val_months;
int val_days;
int lastTwoDigits;
int lastTwoDigitsDIV4;
int The_Day;
int calc_year;
while ( choice=='Y' || choice=='y' )
{
while (flag == 0)
{
printf("Please enter the date :");
scanf ("%d%d%d", &day, &month, &year);
if ( year >= 1900 && year < 2100 )
flag = 1;
else
//invalid_input:
printf ("Please enter a valid date !!!\n");
}//flag while sonu
mod4 = year % 4;
mod100 = year % 100;
mod400 = year % 400;
if (( mod4==0 && mod100!=0 ) || ( mod400==0 ))
isLeap = 1;
else
isLeap = 0;
( isLeap == 1 ) ? (l_d_o_feb = 29) : (l_d_o_feb = 28);
///////////////////////////////////////////////////////////////////////
lastTwoDigits = year % 100;
lastTwoDigitsDIV4 = lastTwoDigits / 4;
if (year >= 1900 && year < 2000)
val_cents = 0;
else
val_cents = 6;
/////////////////Computing The Day of The Week/////////////////////////
/////////////////Computing The Day of The Week/////////////////////////
/////////////////Computing The Day of The Week/////////////////////////
/////////////////Computing The Day of The Week/////////////////////////
switch (month)
{
case 1:
if ( isLeap == 0 )
val_months=0;
else
val_months=6;
break;
case 2:
if ( isLeap == 0 )
val_months=3;
else
val_months=2;
break;
case 3:
val_months=3;
break;
case 4:
val_months=6;
break;
case 5:
val_months=1;
break;
case 6:
val_months=4;
break;
case 7:
val_months=6;
break;
case 8:
val_months=2;
break;
case 9:
val_months=5;
break;
case 10:
val_months=0;
break;
case 11:
val_months=3;
break;
case 12:
val_months=5;
break;
}
The_Day = (val_cents + lastTwoDigits + lastTwoDigitsDIV4 + val_months + day + 1) % 7;
//////////////////// * T H E D A T E * //////////////////////////////
//////////////////// * T H E D A T E * //////////////////////////////
//////////////////// * T H E D A T E * //////////////////////////////
//////////////////// * T H E D A T E * //////////////////////////////
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if (day<1 || day>31)
isValid = 0;
else
{
(day==31) ? month++ , day=1 : day++;
isValid = 1;
}
break;
case 12:
if (day<1 || day>31)
isValid = 0;
else
{
(day==31) ? year++ , day=1 , month=1 : day++;
isValid = 1;
}
break;
case 2 :
if (day<1 || day>l_d_o_feb)
isValid = 0;
else
{
(day==l_d_o_feb) ? month++ , day=1 : day++;
isValid = 1;;
}
break;
case 4:
case 6:
case 9:
case 11:
if (day<1 || day>30)
isValid = 0;
else
{
(day==30) ? month++ , day=1 : day++;
isValid = 1;
}
break;
default:
isValid = 0;
break;
}//switch sonu
///////////////////**********O-U-T-P-U-T*****//////////////////////////
///////////////////**********O-U-T-P-U-T*****//////////////////////////
///////////////////**********O-U-T-P-U-T*****//////////////////////////
///////////////////**********O-U-T-P-U-T*****//////////////////////////
if (isValid == 1)
{
printf ("The next day is %d %d %d ", day, month, year);
switch (The_Day)
{
case 0:
printf ("and it is sunday\n");
break;
case 1:
printf ("and it is monday\n");
break;
case 2:
printf ("and it is tuesday\n");
break;
case 3:
printf ("and it is wednesday\n");
break;
case 4:
printf ("and it is thursday\n");
break;
case 5:
printf ("and it is friday\n");
break;
case 6:
printf ("and it is saturday\n");
break;
}//switch sonu
printf ("------------------------------\nDo you want to continue ? ( y/n ) :");
scanf ( "%c%c" , &choice, &choice );
printf ("------------------------------\n");
}//isValid if sonu
else
printf ("Please enter a valid date !!!\n");
if (choice=='n' || choice =='N')
printf ("Thank you for using my program...\n------------------------------\n");
flag = 0;
}//choice while sonu
system("PAUSE");
return 0;
}