2 date compare
#include <stdio.h>
typedef struct date{
int day;
int month;
int year;
}dt;
dt cmp(dt d1 , dt d2){
if (d1.year>d2.year){
printf("date 1 is born after ");
}
else if(d1.year==d2.year){
if(d1.month>d2.month){
printf("date 1 is born after ");
}
else if(d1.month==d2.month){
if(d1.day>d2.day){
printf("date 1 is born after ");
}
else if(d1.day==d2.day){
printf("both are born on same day");
}
else{
printf("date 1 is born before ");
}
}
else{
printf("date 1 is born before ");
}
}
else{
printf("date 1 is born before ");
}
}
int main() {
// Write C code here
dt day1;
dt day2;
printf("enter the day 1 : ");
scanf("%d",&day1.day);
printf("enter the month 1 : ");
scanf("%d",&day1.month);
printf("enter the year 1 : ");
scanf("%d",&day1.year);
printf("enter the day 2 : ");
scanf("%d",&day2.day);
printf("enter the month 2 : ");
scanf("%d",&day2.month);
printf("enter the year 2 : ");
scanf("%d",&day2.year);
printf("the date is : %d/%d/%d\n",day1.day,day1.month,day1.year);
printf("the date is : %d/%d/%d\n",day2.day,day2.month,day2.year);
cmp(day1 , day2);
return 0;
}
Comments
Post a Comment