Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS151 / KCS251 Programming for Problem Solving - Using C Language
Lab Exercises
34. Write a program to compare two given dates. To store a date uses a structure that contains three members namely day, month and year.
/*
File: Prgrm34.c
Author: Aditya Saini
Date: Jan 19, 2021
Description: Program to compare two given dates. To store a date uses a structure that
contains three members namely day, month and year. If the dates are equal then display
message equal otherwise unequal.
*/
#include <stdio.h>
typedef struct date
{
int day;
int month;
int year;
} date;
int main (void)
{
date A, B;
//Input first date
printf ("Input date A (dd mm yyyy): ");
scanf ("%d %d %d", &A.day, &A.month, &A.year);
//Input second date
printf ("Input date B (dd mm yyyy): ");
scanf ("%d %d %d", &B.day, &B.month, &B.year);
//Check if both dates are equal
if (A.day == B.day && A.month == B.month && A.year == B.year)
printf ("A and B are equal.");
else
printf ("A and B are not equal.");
};
Output
Input date A (dd mm yyyy): 19 01 2021
Input date B (dd mm yyyy): 19 01 2021
A and B are equal.
No comments:
Post a Comment
Please do not post spam links.