Printing the date from starting date to ending date The program takes the starting date and ending date as inputs and prints the dates in between them.This program is useful if u r dealing with dates. The code I have used four date functions i.e date1() , date2() , date3() , date4(). When the starting year and ending year is same it performs date1() function.If the month is equal to starting month then it performs date2() function.If the month is equal to ending month it performs date3() function.If the year is in between starting and ending year then it performs date4() function. Code: #include<iostream> using namespace std; int date1(int , int , int , int , int , int); int date2(int , int , int , int ); int date3(int , int , int , int ); int date4(int , int ); main() { cout<<"Enter the starting date, month and year"<<endl; int sd,sm,sy,ed,em,ey; cin>>sd>>sm>>sy; cout<<"Enter the ending date, month and year"<<endl; cin>>ed>>em>>ey; int i,j,k=0,n,m; n = ey - sy; m=sm-em; if(sy>ey) { cout<<"Starting year cannot be greater than ending year"<<endl; exit(1); } if(n==0&&sm>em) { cout<<"Date entered is wrong"<<endl; exit(1); } if(n==0&&sm>em&&sd>ed) { cout<<"Date entered is wrong"<<endl; exit(1); } if(n==0&&sm==em&&sd>ed) { cout<<"Date entered is wrong"<<endl; exit(1); } if(n==0&&m==0) { cout<<"Month "<<sm<<" Year "<<sy<<endl; for(j=sd;j<=ed;j++) cout<<j<<" "<<endl; exit(1); } if(n==0&&m==0&&sd==ed) { cout<<"Month "<<sm<<" Year "<<sy<<endl; cout<<j<<" "<<endl; exit(1); } if(n==0&&m!=0) { for(j=sm;j<=em;j++) { date1(j,sy,sm,em,sd,ed); } } else {//2 for(i=0;i<=n;i++) {//3 if(i==0) { for(j=sm;j<=12;j++) date2(j,sy,sm,sd); } if(i==n) { for(j=1;j<=em;j++) date3(j,ey,em,ed); } if(i!=0&&i!=n) { for(j=1;j<=12;j++) date4(j,k); } k=sy+1; }//3 }//2 }//1 int date1(int a , int sy , int sm , int em , int sd , int ed ) {// //cout<<"1"<<endl; int i; if(a==2&&sy%4==0&&(a==sm||a==em)) {//1 cout<<"Month "<<a<<" Year "<<sy<<endl; if(a==sm) { for(i=sd;i<=29;i++) cout<<i<<" "; cout<<endl; } if(a==em) { for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } }//1 if(a==2&&sy%4==0&&a!=sm&&a!=em) { cout<<"Month "<<a<<" Year "<<sy<<endl; for(i=1;i<=29;i++) cout<<i<<" "; cout<<endl; } if(a==2&&sy%4!=0&&(a==sm||a==em)) {//2 cout<<"Month "<<a<<" Year "<<sy<<endl; if(a==sm) { for(i=sd;i<=28;i++) cout<<i<<" "; cout<<endl; } if(a==em) { for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } }//2 if(a==2&&sy%4!=0&&a!=sm&&a!=em) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=28;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2==0&&(a==sm||a==em)) {//3 cout<<"Month "<<a<<"Year "<<sy<<endl; if(a==sm) { for(i=sd;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a==em) { for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } }//3 if(a<8&&a!=2&&a%2!=0&&(a==sm||a==em)) {//4 cout<<"Month "<<a<<"Year "<<sy<<endl; if(a==sm) { for(i=sd;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a==em) { for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } }//4 if(a<8&&a!=2&&a%2==0&&a!=sm&&a!=em) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2!=0&&a!=sm&&a!=em) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2==0&&(a==sm||a==em)) {//5 cout<<"Month "<<a<<"Year "<<sy<<endl; if(a==sm) { for(i=sd;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a==em) { for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } }//5 if(a>=8&&a!=2&&a%2!=0&&(a==sm||a==em)) {//6 cout<<"Month "<<a<<"Year "<<sy<<endl; if(a==sm) { for(i=sd;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a==em) { for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } }//6 if(a>=8&&a!=2&&a%2==0&&a!=sm&&a!=em) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2!=0&&a!=sm&&a!=em) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } }// int date2(int a , int sy , int sm , int sd ) {// //cout<<"2"<<endl; int i; if(a==2&&sy%4==0&&a==sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=sd;i<=29;i++) cout<<i<<" "; cout<<endl; } if(a==2&&sy%4==0&&a!=sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=29;i++) cout<<i<<" "; cout<<endl; } if(a==2&&sy%4!=0&&a==sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=sd;i<=28;i++) cout<<i<<" "; cout<<endl; } if(a==2&&sy%4!=0&&a!=sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=28;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2==0&&a==sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=sd;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2==0&&a!=sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2!=0&&a==sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=sd;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2!=0&&a!=sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2==0&&a==sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=sd;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2==0&&a!=sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2!=0&&a==sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=sd;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2!=0&&a!=sm) { cout<<"Month "<<a<<"Year "<<sy<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } }// int date3(int a , int ey , int em , int ed ) {// //cout<<"3"<<endl; int i; if(a==2&&ey%4==0&&a==em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } if(a==2&&ey%4==0&&a!=em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=29;i++) cout<<i<<" "; cout<<endl; } if(a==2&&ey%4!=0&&a==em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } if(a==2&&ey%4!=0&&a!=em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=28;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2==0&&a==em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2==0&&a!=em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2!=0&&a==em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2!=0&&a!=em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2==0&&a==em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2==0&&a!=em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2!=0&&a==em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=ed;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2!=0&&a!=em) { cout<<"Month "<<a<<"Year "<<ey<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } } int date4(int a , int b ) {// //cout<<"4"<<endl; int i; if(a==2&&b%4==0) { cout<<"Month "<<a<<"Year "<<b<<endl; for(i=1;i<=29;i++) cout<<i<<" "; cout<<endl; } if(a==2&&b%4!=0) { cout<<"Month "<<a<<"Year "<<b<<endl; for(i=1;i<=28;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2==0) { cout<<"Month "<<a<<"Year "<<b<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } if(a<8&&a!=2&&a%2!=0) { cout<<"Month "<<a<<"Year "<<b<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2==0) { cout<<"Month "<<a<<"Year "<<b<<endl; for(i=1;i<=31;i++) cout<<i<<" "; cout<<endl; } if(a>=8&&a!=2&&a%2!=0) { cout<<"Month "<<a<<"Year "<<b<<endl; for(i=1;i<=30;i++) cout<<i<<" "; cout<<endl; } }// After entering the starting date and ending date the program checks whether the dates are valid or not.
no response have been given from your side please do it in an easy wayin c.its urgent.i am trying this but i cant do it.so please do it and post it to my email id
Can you please be specific as to what you mean by easy because what could be easy for you could be tough for me and its all relative.
as you have done it in c++ language and i only know c language so i cant understand that solution.so if you will do the solution of that problem iin c language then i will be able to understand that.
Whatever in post.. It's only in C. Can you read article once more time? there is no code of c++ in this article. Please atleast read article and then comment.
Hi gaurav i have written another method for printing the date check it. u can implement this program in c also.First read whole article and understand logic behind the program and try to implement ur own logic for that.