Tuesday, September 9, 2014

compare two dates input by the user, using structure


Problem

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

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct dt_cmp
{
 int day;
 int month;
 int year;
};
main()
{
 struct dt_cmp s[2];
 int i;

 for (i=0;i<2;i++)
 {
  printf ("Enter day : ");
  scanf ("%d",&s[i].day);
  printf ("Enter month : ");
  scanf ("%d",&s[i].month);
  printf ("Enter year : ");
  scanf ("%d",&s[i].year);
 }

 if ( (s[0].day == s[1].day) && (s[0].month == s[1].month) && (s[0].year == s[1].year) )
  printf ("Equal\n");
 else
  printf ("Unequal\n");

 system("pause");
}

Sample Output

compare dates using structres

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact