Chapter - 11: Structures

Write a program that compares two given dates. To store date use structure say the date that contains three members namely date, month and year. If the dates are equal then display the message as "Equal" otherwise "Unequal".


D
Sections
7
Exercises

A

B

C

D

1

2

3

4

5

6

7

8

9

10

11

12

13

#include<stdio.h>
#include<conio.h>
struct dmy
{
	int date;
	int month;
	int year;
};

int datcmp(struct dmy a, struct dmy b)
{
	if (a.date == b.date && a.month == b.month && a.year == b.year)
		return 0;
	else
		return 1;
}

int main()
{
	struct dmy a, b;
	int flag;
	printf("\nEnter the first date (dd mm yyyy) : ");
	scanf("%d%d%d", &a.date, &a.month, &a.year);
	printf("\nEnter the second date (dd mm yyyy) : ");
	scanf("%d%d%d", &b.date, &b.month, &b.year);
	flag = datcmp(a, b);
	if (flag)
		printf("\nThe dates are not same\n");
	else
		printf("\nThe dates are same\n");
	_getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo