answer.
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
-Dominant- [34]
2 years ago
6

Write a program that reads an integer value from the user representing a year. The purpose of the program is to determine if the

year is a leap year (and therefore has 29 days in February) in the Gregorian calendar. A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not 400. For example, the year 2003 is not a leap year, but 2004 is. The year 1900 is not a leap year because it is divisible by 100, it is also divisible by 400. Produce an error message for any input value less than 1582 (the year the Gregorian calendar was adopted).
Computers and Technology
1 answer:
timofeeve [1]2 years ago
3 0

Answer:

Following program in c language:

#include <stdio.h> // header file

int main() // main method

{

   int year1 ; // varuiable declaration

   printf("Enter year: ");

   scanf("%d",&year1); // input year

   if(year1<1582) // checking condition if year less then 1582

   {

   printf(" invalid year please input correct year");

}

else

{

   if(year1 % 4 == 0) // checking condition of leap year  

   {

       if( year1 % 100 == 0) // checking condition of leap year  

       {

           if ( year1 % 400 != 0)  

               printf("%d is a Leap Year", year1);

           else

               printf("%d is not a Leap Year", year1);

       }

       else

           printf("%d is a Leap Year", year1 );

   }

   else

       printf("%d is not a Leap Year", year1);

}

   return 0;

}

Output:

First output

Enter year:  2004

2004 is a leap year

Second output

Enter year:  2003

2003 is not a leap year

Third output

Enter year:  200

invalid year please input correct year

Explanation:

In this program we input a year by user in "year1" variable .Initially check if year is less then 1582 then display message in console " invalid year please input correct year" otherwise control moves to else block and check the condition which is given below.

A year is leap year if it is satisfied these condition

(year1 % 4 == 0) and (year1 % 100 == 0) and  (year1 % 400 != 0)

Otherwise it is not a leap year.

You might be interested in
First, open two separate terminal connections to the same machine, so that you can easily run something in one window and the ot
dusya [7]
Dnt listen to da file shi
7 0
2 years ago
Robin wants her presentation to move from one slide to another with special motion effects. Which option should Robin use?
topjm [15]
If this is in power point, then she should use the <em>transitions </em>tab on the ribbon. =)
3 0
2 years ago
Read 2 more answers
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
harina [27]

Answer:

One of the strategies to avoid nested conditional is to use logical expressions such as the use of AND & operator.

One strategy is to use an  interface class with a method. That method can be created to be used for a common functionality or purpose. This is also called strategy design pattern. You can move the chunk of conditional statement to that method. Then each class can implement that interface class and use that shared method according to their own required task by creating objects of sub classes and call that common method for any such object. This is called polymorphism.

Explanation:

Nested conditionals refers to the use of if or else if statement inside another if or else if statement or you can simply say a condition inside another condition. For example:

if( condition1) {  

//executes when condition1 evaluates to true

 if(condition2) {

//executes when condition1  and condition2 evaluate to true

 }  else if(condition3) {

 //when condition1 is true and condition3 is true

} else {

 //condition1  is true but neither condition2 nor conditions3 are true

}  }

The deeply nested conditionals make the program difficult to understand or read if the nested conditionals are not indented properly. Also the debugging gets difficult when the program has a lot of nested conditionals.

So in order to avoid nested conditionals some strategies are used such as using a switch statement.

Here i will give an example of one of the strategies i have mentioned in the answer.

Using Logical Expressions:

A strategy to avoid nested conditionals is to use logical expressions with logical operators such as AND operator. The above described example of nested conditionals can be written as:

if(condition1 && condition2){  //this executes only when both condition1 and condition2 are true

} else if(condition1 && condition3) {

this executes only when both condition1 and condition3 are true

} else if(condition1 ){

//condition1  is true but neither condtion2 nor condtion3 are true  }

This can further be modified to one conditional as:

if(!condition3){

// when  condition1 and condition2 are true

}

else

// condition3 is true

Now lets take a simple example of deciding to go to school or not based on some conditions.

if (temperature< 40){

  if (busArrived=="yes")   {

      if (!sick)       {

          if (homework=="done")           {

              printf("Go to school.");

          }

      }     

  }

}

This uses nested conditionals. This can be changed to a single conditional using AND logical operator.

if ((temperature <40) && (busArrived=="yes") &&

(!sick) && (homework=="done"))

{    cout<<"Go to school."; }

6 0
2 years ago
Ethan is a systems developer. He is working on a system where he will implement independent solutions for different processes. W
Igoryamba
The correct answer for this question is this one: " c.huge initial investment"
<span>Ethan is a systems developer. He is working on a system where he will implement independent solutions for different processes. The possible drawback of using such a system is that </span><span><u>huge initial investment</u>
</span>
Hope this helps answer your question and have a nice day ahead.
8 0
2 years ago
Write a program that repeatedly reads in integers until a negative integer is read. The program keeps track of the largest integ
vfiekz [6]

Answer:

In Python:

num = int(input("Enter number: "))

maxn = num

while num >=0:

   if num>maxn:

       maxn = num

   num = int(input("Enter number: "))

print("Largest: "+str(maxn))

Explanation:

Get input from the user

num = int(input("Enter number: "))

Initialize the largest to the first input

maxn = num

This loop is repeated until a negative input is recorded

while num >=0:

If the current input is greater than the previous largest

   if num>maxn:

Set largest to the current input

       maxn = num

Get another input from the user

   num = int(input("Enter number: "))

Print the largest

print("Largest: "+str(maxn))

5 0
2 years ago
Other questions:
  • Allows you to manually add an entry to the arp cache that resolves the ip address inetaddr to the physical address etheraddr. wh
    13·1 answer
  • Which technology had the same effect in the 1920s as the internet did in the 2000s? the widespread effect of technology 1920s 20
    8·1 answer
  • Templates contain common layout and formatting that can save you time by not having to recreate documents from scratch. True or
    10·1 answer
  • Describe two reasons to use the Internet responsibly. Explain what might happen if the Internet use policies were broken at your
    12·2 answers
  • George borrowed some equipment from his friend for recording his monologue for his art class. He got all the equipment except th
    15·1 answer
  • The OSI security architecture provides a systematic framework for defining security attacks, mechanisms, and services. True or F
    12·1 answer
  • The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the
    11·1 answer
  • Suppose that a class named ClassA contains a private nonstatic integer named b, a public nonstatic integer named c, and a public
    14·1 answer
  • Janice has a "jammed" key on her keyboard. Every time she strikes the "S" key it sticks and doesn't pop back. What should Janice
    6·2 answers
  • In this problem, you will derive the efficiency of a CSMA/CD-like multiple access protocol. In this protocol, time is slotted an
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!