Object

Write a program to read the dates of birth of two persons and determine who is younger.

Algorithm

  1. Declare integer variables d1, m1, y1, d2, m2 and y2.
  2. Read d1, m1, y1, d2, m2 and y2
  3. IF (y1=y2 and m1=m2 and d1=d2), then
    • Write “The dates of birth of both persons are same”.
      • ELSE IF (((y1=y2) and (m1=m2) and (d1>d2)) or ((y1=y2) and (m1>m2)) or (y1>y2)), then
        • Write “The first person is younger”.
      • ELSE
        • Write “The second person is younger”.
      • [End of IF-ELSE structure.]
  4. Exit.

Flowchart

C++ Source Code

// program 27
#include<iostream>
using namespace std;

int main()
{
  int d1, d2, m1, m2, y1, y2;
  cout << "Enter the date of birth of first person (dd mm yyyy): ";
  cin >> d1 >> m1 >> y1;
  cout << "Enter the date of birth of second person (dd mm yyyy): ";
  cin >> d2 >> m2 >> y2;

  if ((y1 == y2) && (m1 == m2) && (d1 == d2))
    cout << "The dates of birth of both persons are the same.";
  else if (((y1 == y2) && (m1 == m2) && (d1 > d2)) || ((y1 == y2) && (m1 > m2)) || (y1 > y2))
    cout << "The first person is younger.";
  else
    cout << "The second person is younger.";
  return 0;
}

C Source Code

/*program 27*/
#include <stdio.h>

int main() 
{
  int d1, d2, m1, m2, y1, y2;
  printf("Enter the date of birth of first person (dd mm yyyy): ");
  scanf("%d %d %d", &d1, &m1, &y1);
  printf("Enter the date of birth of the second person (dd mm yyyy): ");
  scanf("%d %d %d", &d2, &m2, &y2);

  if ((y1 == y2) && (m1 == m2) && (d1 == d2))
    printf("The dates of birth of both persons are the same.\n");
  else if (((y1 == y2) && (m1 == m2) && (d1 > d2)) || ((y1 == y2) && (m1 > m2)) || (y1 > y2))
    printf("The first person is younger.\n");
  else
    printf("The second person is younger.\n");
  
  return 0;
}

Output

Enter the date of birth of first person (dd mm yyyy): 14 6 1972
Enter the date of birth of second person (dd mm yyyy): 23 2 1974
The second person is younger.

Design a site like this with WordPress.com
Get started