In this program user enters two dates for comparison. In order to store date we will use structure say date that contains three members namely date, month and year. If the dates are equal then display message as “Dates are Same." otherwise “Both the dates are different”.
void main()
{
int i, f = 0;
struct date
{
int date;
int month;
int year;
};
struct date d[2];
for(i = 0; i < 2; i++)
{
printf("\n Enter day for the %d date \n", i + 1);
scanf("%d",&d[i].date);
printf("\n Enter the month for the %d) date \n", i + 1);
scanf("%d",&d[i].month);
printf("\n Enter the year for the %d) date \n", i + 1);
scanf("%d",&d[i].year);
}
if(d[0].date == d[1].date)
{
if(d[0].month == d[1].month)
{
if(d[0].year == d[1].year)
{
f = 1;
}
}
}
if(f == 1)
printf("\nDates are Same.");
else
printf("\nBoth the dates are different.");
}
ALSO CHECK THESE C PROGRAMS:
- C Program to count the number of words, characters, alphabets, vowels, consonants and digit in a line of text.
- C Program to accept two string and compare the strings are equal or not.
- C Program to sort the entered numbers using bubble sort.
- C Program To Implement Minimum Spanning Tree Using Functions, Pointers & Structures.
- C Program To Implement 8 Queens Problem Using Arrays, Pointers & Functions.
- C Program To Implement Quick Sort Using Pointers, Functions & Arrays.
...Back To C Program Index.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com