![Jcmandique4062](/avatars/18493.jpg)
Jcmandique4062
18.06.2021 •
Computers and Technology
Write a program that accepts a date in the form month/day/year and outputs whether or not the date is valid. For example, 5/24/1962 is valid, but 9/31/2000 is not. (September has only 30 days.)
Solved
Show answers
More tips
- G Goods and services What Are the Most Popular Services?...
- P Philosophy How did the concept of module arise in computer science?...
- D Dating, Love, Relationships Why Should the Man be Active and the Woman Passive during Foreplay?...
- S Society and Politics Выборы: Смысл, Значение и Отражение...
- B Business and Finance How to Get Your Money Back When Lending? Top 7 Ways...
- F Family and Home Do Lullabies Help Babies Sleep or Is it Just a Myth?...
- F Family and Home Why Does God Punish Us Constantly and How Can We Fix It?...
- D Dating, Love, Relationships Why do we feel shame?...
- S Society and Politics How Could Nobody Know About the Dead Mountaineers?...
- O Other How to Accidentally Get a Rare Coin with Your Change and How to Know Its Value?...
Answers on questions: Computers and Technology
- C Computers and Technology When creating a shape in Word, what are some available options? Check all that apply. adding text to the shape changing the size of the shape changing the location of the shape...
- C Computers and Technology Copy the program file Notepad.exe from the \Windows directory on the hard drive to the \Tools directory on the flash drive. What command did you use...
- C Computers and Technology Explain the danger leaks pose when operating a tractor....
- M Mathematics 2 pungi de aceeași capacitate contin rosii si lana.Care are masa mai mare?...
- E English It isn t very hot today...
- M Mathematics Which algebraic expression represents the difference of e squared and twenty-one? A. E2+21 b.21 times e2 c. E2 - 21 d. 21 divided by e2...
- W World Languages Fill in the blank with the word or phrase that best completes the sentence Scripta , pater cubitum ivit a. litteram b. litterae c. litteras d. littera...
- S Social Studies Indian nationalism helped spark the Indian Indepence movement from (country) in (year)....
- M Mathematics What is the value of h? The graph shows that f(x) = 3* is translated horizontally and vertically to create the function g(x) = 3x - h+k. -2 - 1 T ОООО 1 fo) g) 2 -2 -1...
- S Social Studies Why did Hitler reject the Treaty of Versailles A. It declared the Weimar Republic the rightful governing body over Germany B. It forced Germany to demilitarize completely and hand...
Ответ:
Here is the code.
Explanation:
#include <stdlib.h>
#include <stdio.h>
int check_month(int month);
int check_date(int year, int month, int day);
void display_date(int year, int month, int day);
int check_year(int year);
int main (void)
{
int year, month, day;
int valid;
printf("\t\t\t\tEnter Date \n");
printf("\nyear (): ");
scanf("%d",&year);
printf("month: ");
scanf("%d",&month);
printf("day: ");
scanf("%d", &day);
valid = check_month(month);
if (valid)
{
valid = check_date(year, month, day);
}
if (valid)
{
display_date(year, month, day);
printf("is a valid date. \n");
}
else
{
display_date(year, month, day);
printf("is a illegal date. \n");
}
system ("pause");
return 0;
}
int check_month(int month)
{
int flag;
if (month>=1 && month<=12)
flag = 1;
else
flag = 0;
return flag;
}
int check_date(int year, int month, int day)
{
int valid;
int leep_year;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (day>=1 && day<=31)
valid = 1;
else
valid = 0;
break;
case 2:
leep_year = check_year(year);
if (leep_year)
{ if (day>=1 && day<=29)
valid = 1;
else
valid = 0;
}
else
{ if (day>=1 && day<=28)
valid = 1;
else
valid = 0;
}
break;
case 4:
case 6:
case 9:
case 11:
if (day>=1 && day<=30)
valid = 1;
else
valid = 0;
break;
}
return valid;
}
int check_year(int year)
{
int leep_year;
if (year%4==0)
{
if (year%100==0)
{
if (year%400==0)
leep_year = 1; // 1600, 2000
else
leep_year = 0; // 1700, 1800, 1900, 2100
}
else
{
leep_year = 1; // 2004, 1996
}
}
else
{
leep_year = 0; // 2003, 2011
}
return leep_year;
}
void display_date(int year, int month, int day)
{
if (month == 1)
printf("January");
else if (month == 2)
printf("February");
else if (month == 3)
printf("March");
else if (month == 4)
printf("April");
else if (month == 5)
printf("May");
else if (month == 6)
printf("June");
else if (month == 7)
printf("July");
else if (month == 8)
printf("August");
else if (month == 9)
printf("September");
else if (month == 10)
printf("October");
else if (month == 11)
printf("November");
else if (month == 12)
printf("December");
else
printf("The Month enter is not valid.\n");
printf(" %d, %d ",day,year);
}
Ответ: