Tuesday, 7 May 2013

Program In C To Print Next Date


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ int d1,m1,d2,m2,y1,y2;
clrscr();
printf("Enter The Date: ");
scanf("%d",&d1);
printf("Enter The Month: ");
scanf("%d",&m1);
printf("Enter The Year: ");
scanf("%d",&y1);
if((d1>=1&&d1<28))
{ d2=d1+1;
m2=m1;
y2=y1; }
else if((d1==31)&&(m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12))
{ d2=1;
 if(m1==12)
{
m2=1;
y2=y1+1; }
else
{ m2=m1+1;
y2=y1; }}
else if((m1==2)&&(d1<30))
{ if((y1%4==0&&d1==29)||(y1%4!=0&&d1==28))
{ d2=1;
m2=3;
y2=y1; }
else if(d1<29)
{ d2=d1+1;
m2=2;
y2=y1; }}
else if((d1==30)&&(m1==4||m1==6||m1==9||m1==11))
{d2=1;
m2=m1+1;
y2=y1; }
else if((m1<13&&d1<31)&&(m1!=2))
{ d2=d1+1;
m2=m1;
y2=y1;
}
else
{ printf("Wrong Date !!!!!");
exit(0);
}
printf("Next Date Is: %d.%d.%d",d2,m2,y2);
getch();
}

No comments:

Post a Comment