BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to print date of birth using structure

Last Updated: May 18, 2024 by Chaitanya Singh | Filed Under: C Programs

In this guide, we will learn how to write a C program to print date of birth using structure. This program will help you understand the usage of structure.

C Program to print a person’s date of birth using structure

The explanation of this program is provided at the end of the code along with the output.

#include <stdio.h>

// Define a structure to hold a date
struct Date {
int day;
int month;
int year;
};

int main() {
// Declare a variable dob of type Date
struct Date dob;

// Input the date of birth and store in structure
printf("Enter date of birth (DD/MM/YYYY): ");
scanf("%d/%d/%d", &dob.day, &dob.month, &dob.year);

// Print the date of birth
printf("Date of birth: %02d/%02d/%d\n", dob.day, dob.month, dob.year);

return 0;
}

Explanation:

  1. Structure Definition:
    • We define a structure named Date to hold day, month, and year. This is where we will store the input date, which we can later retrieve it using the dob variable.
  2. Main Function:
    • We declare a variable dob of type Date to store the date of birth in the structure Date.
    • The program prompts the user to input the date of birth in the format DD/MM/YYYY.
    • The scanf function reads the input and stores the values in structure Date using dob variable.
  3. Output:
    • The program fetches the data from structure Date using dob variable and prints the date of birth using the printf function, formatting the output as DD/MM/YYYY.

Output:

Enter date of birth (DD/MM/YYYY): 15/05/1990
Date of birth: 15/05/1990

Top Related Articles:

  1. C Program to print current date and time
  2. C Program to Convert time from 24 hour to 12 hour format
  3. C Program to convert a time from 12 hour to 24 hour format
  4. C Program to read and print employee details using structure
  5. C Program to multiply two complex numbers using structure

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap