Write a program that defines a:
- date type
- function that prints a date
- function that creates and returns the date after one year
Write a main function to test your functions.
Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
typedef struct {
int day;
int month;
int year;
} date;
void display_date(date d)
{
printf("%d/%d/%d\n", d.day, d.month, d.year);
}
date next_year(date d)
{
date r;
r.day = d.day;
r.month = d.month;
r.year = d.year+1;
return r;
}
void main(void) {
date d1 = { 12, 1, 2020 }; /* 12 january 2020 */
date d2;
display_date(d1);
d2 = next_year(d1);
display_date(d2);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Checking whether a given binary tree is a BST