//Program to find the name of day when a date is given
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main(){
int d,m,y,i;
int r,r1=0,r2=0,s=0;
input:
printf("\nEnter the DAY MONTH and YEAR:\n");
scanf("%d %d %d",&d,&m,&y);
if(m==2){
if((d>28)&&(y%4!=0)){
printf("\nFool,Invalid date in February of non leap year.The maximum value is 28.\n");
goto input;
}
if((d>29)&&(y%4==0)){
printf("\nFool,Invalid date in February of leap year.The maximum value is 29.\n");
goto input;
}
}
else if((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10)||(m==12)){
if(d>31){
printf("\nFool,Invalid date in %d th month.The maximum value is 31.\n",m);
goto input;
}
}
else if(((m==4)||(m==6)||(m==9)||(m==11))&&(d>30)){
printf("\nFool,Invalid date in the %d th month.The maximum value is 30.\n",m);
goto input;
}
else if((d>31)){
printf("\nEnter valid date.\n");
goto input;
}
if((d<1)||(m<1)){
printf("\nFool,Enter positive valid data.\n");
goto input;
}
else {
switch(m){
case 1:
case 10:
r1=d+2;
break;
case 2:
case 3:
case 11:
r1=d+5;
break;
case 4:
case 7:
r1=d+1;
break;
case 9:
case 12:
r1=d;
break;
case 5:
r1=d+3;
break;
case 6:
r1=d+6;
break;
case 8:
r1=d+4;
break;
default:
{
printf("\nDon't U know that there is no month greater than 12.Enter valid month Once again enter the Date Month Year.\n");
goto input;
}
}
}
if(y<2003){
for(i=2002;i>=y;i--){
if((i==y)&&(i%4==0)){
if(m>2) s=s+1;
else if(m<=2) s=s+2;
break;
}
else if(i%4==0){
if(i%100==0){
if(i%400==0)
s=s+2;
else s=s+1;
}
else s=s+2;
}
else s=s+1;
}
r2=7-s%7;
}
else if(y>2003){
for(i = 2004; i <= y; i++){
if((i==y) && (i%4 == 0)){
if(m > 2) s = s+2;
else if(m<=2) s=s+1;
break;
}
else if(i%4==0){
if(i%100==0){
if(i%400==0)
s=s+2;
else s=s+1;
}
else s=s+2;
}
else s=s+1;
}
r2=s%7;
}
else r2=0;
r=(r1+r2)%7;
printf(" ");
switch(r){
case 0:
printf("\nThe Day is SUNDAY.");
break;
case 1:
printf("\nThe Day is MONDAY.");
break;
case 2:
printf("\nThe Day is TUESDAY.");
break;
case 3:
printf("\nThe Day is WEDNESDAY.");
break;
case 4:
printf("\nThe Day is THURSDAY.");
break;
case 5:
printf("\nThe Day is FRIDAY.");
break;
case 6:
printf("\nThe Day is SATURDAY.");
break;
}
printf("\tThanks for using my program !");
getch();
}
-> you can find the name of the day on entering a specific date.
No comments:
Post a Comment