The Program in C to Create a Date structure,increase date by Addition No. of days ,date should be valid input given by user is given below:
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
int main() {
struct Date date;
int daysToAdd;
// Get user input for date
printf("Enter day: ");
scanf("%d", &date.day);
printf("Enter month: ");
scanf("%d", &date.month);
printf("Enter year: ");
scanf("%d", &date.year);
printf("Enter number of days to add: ");
scanf("%d", &daysToAdd);
// Add days to date
date.day += daysToAdd;
// here you can put your logic for adding days to date , month, year
// Display resulting date
printf("Resulting date: %d/%d/%d\n", date.day, date.month, date.year);
return 0;
}
Output:
Enter day: 5
Enter month: 6
Enter year: 1999
Enter number of days to add: 14
Resulting date: 19/6/1999
Pro-Tips💡
In the main function, an instance of the struct is created and user input is requested for the day, month, and year of the date and the number of days to add to the date.
The input is stored in the struct instance using the “scanf” function.
The “day” variable of the struct is then incremented by the number of days to add.
The resulting date is then displayed in the format “day/month/year” using the “printf” function. The program ends with a return statement of 0.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.