C Examples

WAP in C to Create a Date structure,increase date by Addition No. of days ,date should be valid input given by user!

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

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

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X