1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Papessa [141]
3 years ago
6

4) Days in a Month Write a C program that asks the user to enter the month (letting the user enter an integer in the range of 1

through 12) and the year. The program should then display the number of days in that month. Use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and only if it is divisible by 400. For example, 2000 is a leap year but 2100 is not. 2. If the year is not divisible by 100, then it is a leap year if and if only it is divisible by 4. For example, 2008 is a leap year but 2009 is not. Remember that January, March, May, July, August, October and December have 31 days. April, June, September, November have 30 days. Use ints for the month and year.
Computers and Technology
1 answer:
adoni [48]3 years ago
7 0

Answer:

// program in C

#include <stdio.h>

int main()

{

   // variable

  int m,y;

  int days;

  // validate month

  do

  {

      printf("Enter a month (1-12) : ");

         // read month

      scanf("%d",&m);

  }while(m<=0 || m >12);

  printf("Enter a year : ");

     // read year

  scanf("%d",&y);

// months in which days are 30

  if (m == 4 || m == 6 || m == 9 || m == 11)

      days = 30;

// if month is feb

  else if (m == 2)

  {

         // check leap year

      if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))        

          days = 29;

      else

          days = 28;

  }

  // month in which days are 31

  else

      days = 31;

// print days in the given month

  printf("Number of days:%d",days);

return 0;

}

Explanation:

Read month from user.If entered month is not from 1-12 then ask until user enter  a valid month.Read year from user.After this if month is 4,6,9 or 11 then days  in the month are 30.If the month is 2 then check year is leap or not.If year is leap  then 29 day else 28 days.If month is other than this then days are 31.

Output:

Enter a month (1-12) : 2                                                                                                  

Enter a year : 2008                                                                                                        

Number of days:29

You might be interested in
Im lonnnelllly........................who want to date
blsea [12.9K]
Hey just a word of advice I hope you find someone lovely and someone who’ll enjoy you for you. Don’t look for people on apps like this I made many mistakes and it’s not smart. Have a good day. I get the feeling of loneliness and it sucks
8 0
3 years ago
Which does plug-and-play refer to?
vlabodo [156]
The answer is c the ability for the os to detect
7 0
3 years ago
It is considered good practice to save a presentation before printing it. true false
Ilya [14]
It is true because it is really a good practise to save a presentation before printing it

5 0
3 years ago
List four tasks that humans perform frequently, but which may be difficult for a computerized agent to accomplish. Describe the
denis23 [38]

Answer:

im sorry for that

Explanation:

5 0
2 years ago
What are the five layers in the internet protocol stack? What are the principal responsibilities of each of these lay?
mariarad [96]

Solution:

The five Layers in Internet protocol stack are:

1.Application Layer  

2.Transport Layer  

3.Network Layer  

4.Link Layer  

5.Physical Layer  

The principal responsibilities of these layers are as follows:

1.Application Layer •Applications with appropriate requirement for user.  

•It is reserved for network applications and their application protocols such as HTTP, SMTP, and FTP etc.  

•Its protocol uses transport layer protocols for establishing host-to-host connection.  

2.Transport Layer  

•It is responsible for End-to-Communication  

•Transport layer transports messages from application layer between client and server of application  

•It uses two protocol for transporting messages: TCP and UDP.TCP provides reliable connection oriented services, while UDP provides connectionless service  

3.Network Layer  

•Network Layer moves packets from one host to destination.

•It has two principal component:IP protocol:-It defines the datagrams and decide how the end system and router will work Routing protocols: these protocols decide the routing path between source and destination. 4.Link Layer  

•It is responsible for link-level communication  

•Link layer receives the data gram from network layer at each node and delivers it to next node, the next node passes the datagram to network layer.so This layer moves entire frames from one network element to adjacent one.

•The service provided by link layer is protocol dependent

5.Physical Layer  

•It provides Physical media

•At each node, it moves individual bits of frames to next node.  


7 0
3 years ago
Other questions:
  • What keyboard shortcut keys selects cell A1
    12·1 answer
  • 13. You're expecting an important call from Mr. Suarez, a potential customer. While waiting for this call, your supervisor calls
    15·1 answer
  • A security policy is a
    11·1 answer
  • "what are the problems with tcp over wireless network?"
    15·1 answer
  • Another html/css assignment, drop css code below, thank you
    15·1 answer
  • Once a software program has been through one test cycle performed by the programmers and is running proper
    10·1 answer
  • What is copy and paste?
    13·2 answers
  • An address has a house number, a street, an optional apartment number, a city, a state and a postal code. Define the constructor
    5·1 answer
  • Data is best described as
    10·2 answers
  • There are parallels between the trust models in Kerberos and Public Key Infrastructure (PKI). When we compare them side by side,
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!