C Program to Print the Next Date दी गई Date की अगली Date Print करने का C Program

In C language, we can write a program to calculate the next date when a date is given by the user. The program checks the number of days in the given month and updates the day, month, and year accordingly.

C भाषा में हम ऐसा program बना सकते हैं जो user द्वारा दी गई date की अगली date calculate करता है। यह program month में दिनों की संख्या जाँचकर day, month और year को update करता है।

C Program

#include <stdio.h>
int main(void)
{
int dd, mm, yyyy, nd, nm, ny, ndays;
printf("Enter day, month and year\n");
scanf("%d%d%d", &dd, &mm, &yyyy);
switch (mm)
{
case 1: case 3: case 5: case 7:
case 8: case 10: case 12:
ndays = 31;
break;
case 4: case 6: case 9: case 11:
ndays = 30;
break;
case 2:
if ((yyyy % 400 == 0) ||
(yyyy % 4 == 0 && yyyy % 100 != 0))
ndays = 29;
else
ndays = 28;
break;
default:
printf("Invalid month\n");
return 0;
}
if (yyyy < 1 || dd < 1 || dd > ndays)
{
printf("Invalid date\n");
return 0;
}
nd = dd + 1;
nm = mm;
ny = yyyy;
if (nd > ndays)
{
nd = 1;
nm++;
}
if (nm > 12)
{
nm = 1;
ny++;
}
printf("Given date is %d/%d/%d\n", dd, mm, yyyy);
printf("Next date is %d/%d/%d\n", nd, nm, ny);
return 0;
}

Output

Example 1:

Enter day, month and year
15 8 2025
Given date is 15/8/2025
Next date is 16/8/2025

Example 2:

Enter day, month and year
31 12 2025
Given date is 31/12/2025
Next date is 1/1/2026

Example 3:

Enter day, month and year
28 2 2024
Given date is 28/2/2024
Next date is 29/2/2024

Explanation

  • switch(mm) determines the maximum number of days in the given month.

  • ndays stores the number of days in that month.

  • nd = dd + 1 calculates the next day.

  • If nd exceeds ndays, the day becomes 1 and the month increases by 1.

  • If the month becomes greater than 12, it changes to 1 and the year increases by 1.

switch(mm) month के अनुसार उस month में दिनों की संख्या निर्धारित करता है। nd = dd + 1 अगला दिन calculate करता है। यदि day month के अंतिम दिन से आगे बढ़ जाता है, तो day 1 और month अगले month में चला जाता है। December के बाद year भी increase हो जाता है।

Modern C Compatibility Note

This program uses standard C and is compatible with modern compilers such as GCC, Clang, and Visual Studio C. It does not require conio.h, clrscr(), or getch().

Note: This program validates the day and month and checks for a positive year. It does not enforce a specific year range.

This program demonstrates how to calculate the next date using switch, if statements, and date-related logic in C.

यह program C भाषा में switch और if statements का उपयोग करके दी गई date की अगली date calculate करना सिखाता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025