0% found this document useful (0 votes)
12 views3 pages

C Lab1

This lab report describes a C program that checks if a date entered by the user is valid or not. It takes in the day, month, and year as input, then performs a series of checks to determine if the date is valid depending on the month and year. These include checks for the range of the day and month numbers, determining if the year is a leap year, and validating the day against the number of days in each month. It then prints either "Date is valid" or "Date is not valid" based on the results of the checks.

Uploaded by

rashed ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

C Lab1

This lab report describes a C program that checks if a date entered by the user is valid or not. It takes in the day, month, and year as input, then performs a series of checks to determine if the date is valid depending on the month and year. These include checks for the range of the day and month numbers, determining if the year is a leap year, and validating the day against the number of days in each month. It then prints either "Date is valid" or "Date is not valid" based on the results of the checks.

Uploaded by

rashed ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Report

Course Title : Structured Programming Language Lab


Course Code : CSE 102
Lab Report No. : 01

Submitted by Submitted to
Rashed Ahmed Hridoy Samin Yasar
ID: 20245103289 Department of Computer Science
and Engineering
Intake: 53
Section: 8
Department of CSE

Date of Submission: 06/02/2024


▪ A program to check whether the entered date is valid or not.

Code:
#include<stdio.h>
int main()
{
int d,m,y;
printf("Enter day: ");
scanf("%d",&d);
printf("Enter month: ");
scanf("%d",&m);
printf("Enter year: ");
scanf("%d",&y);
if(d>0 && d<32 && m>0 && m<13)
{
if(m==2)
{
if((y%4==0 && y%100!=0)||y%400==0)
{
if(d<30)
printf("Date is valid");
else
printf("Date is not valid");
}
else
{
if(d<29)
printf("Date is valid");
else
printf("Date is not valid");
}
}
else if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
{
if(d<32)
printf("Date is valid");
else
printf("Date is not valid");
}
else
{
if(d<31)
printf("Date is valid");
else
printf("Date is not valid");
}
}
else
printf("Date is not valid");
return 0;
}

Explanation:
This a program that checks if the date entered by the user is valid or not.

The program starts by asking the user to input a day (d), month (m), and year (y).

It then checks if the day is between 1 and 31 and the month is between 1 and 12.
If not, it prints "Date is not valid" and ends.

If the month is February (m==2), it checks if the year is a leap year. A leap year is
either divisible by 400 or divisible by 4 but not by 100. If it is a leap year, it checks if
the day is less than or equal to 29. If it's not a leap year, it checks if the day is less
than or equal to 28. If these conditions are met, it prints "Date is valid", else it prints
"Date is not valid".

If the month is one that has 31 days (January, March, May, July, August, October, or
December), it checks if the day is less than or equal to 31. If not, it prints "Date is
not valid".

If the month is one that has 30 days (April, June, September, or November), it checks
if the day is less than or equal to 30. If not, it prints "Date is not valid".
If one of the above conditions is met, it prints "Date is valid".

You might also like