Question

In: Computer Science

Basically if the year is divisible by 4( think year%4==0) it’s a leap year UNLESS its...

Basically if the year is divisible by 4( think year%4==0) it’s a leap year UNLESS its divisible by 100 in which case its not a leap year UNLESS its also divisible by 400 , in which case it is.

Write a program that evaluates the years from 1890 to 2017 and write out the year if it is a leap year. Otherwise do not write out anything.

Hints

  1. Loops can begin at any integer(think begin at 1890; test will be year <=2017)
  2. Use && and || to get desired result in the if statements
  3. There is nothing to write out in the case its not a leap year. If none of the conditions for a leap year are true, the loop “block” would end and you would increment , test to see if less than 2017 and then evaluate the next year.

Here is what the output should look like

1892 is a leap year

1896 is a leap year

1904 is a leap year

1908 is a leap year

1912 is a leap year

1916 is a leap year

1920 is a leap year

1924 is a leap year

1928 is a leap year

1932 is a leap year

1936 is a leap year

1940 is a leap year

1944 is a leap year

1948 is a leap year

1952 is a leap year

1956 is a leap year

1960 is a leap year

1964 is a leap year

1968 is a leap year

1972 is a leap year

1976 is a leap year

1980 is a leap year

1984 is a leap year

1988 is a leap year

1992 is a leap year

1996 is a leap year

2000 is a leap year

2004 is a leap year

2008 is a leap year

2012 is a leap year

2016 is a leap year

Solutions

Expert Solution

Given in the question, if the year is divisible by 4( think year%4==0) it’s a leap year UNLESS its divisible by 100 in which case its not a leap year UNLESS its also divisible by 400 , in which case it is. Following is the code:

In Python

def check(year):
    if (year % 400) == 0:
        return True
        
    if (year % 100) == 0:
        return False
        
    if (year % 4) == 0:
        return True
        
    return False
 
for y in range(1890, 2018):
    if(check(y)):
        print(y, "is a leap Year")

In Java

public class MyClass {
    public static boolean check(int year)
    {
        if (year % 400 == 0)
            return true;
     
        if (year % 100 == 0)
            return false;
     
        if (year % 4 == 0)
            return true;
        
        return false;
    }
    
    
    public static void main(String args[]) {
      
      for(int i=1890; i<=2017; i++) {
          if(check(i)) {
               System.out.println(i + " is a leap year");
          }
      }
    }
}

In C++

#include <iostream>
using namespace std;

bool check(int year) 
{
    if (year % 400 == 0) 
        return true; 

    if (year % 100 == 0) 
        return false; 

    if (year % 4 == 0) 
        return true; 
    
    return false; 
} 
int main() {
    for(int i=1890; i<=2017; i++) {
        if(check(i)) {
            cout<<i<<" is a leap year\n";
        }
    }
}

Related Solutions

TABLE 4 Project Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Cash...
TABLE 4 Project Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Cash Flow Cash Flow Cash Flow Cash Flow Cash Flow Cash Flow A -15000 6000 7000 6000 6000 6000 B -15000 7000 7000 7000 7000 7000 C -18000 12000 2000 2000 2000 2000 "Consider the cash flow of the three projects depicted in Table 4. The cost of capital is 7.5%. If an investor decided to take projects with a payback period of 2 years...
Project Year 0 Year 1 Year 2 Year 3 Year 4 A    -$ 49 $ 25...
Project Year 0 Year 1 Year 2 Year 3 Year 4 A    -$ 49 $ 25 $ 22 $ 22 $ 15 B -$ 101 $ 19 $ 39 $ 51 $ 61 a. What are the IRRs of the two​ projects? b. If your discount rate is 4.8%​, what are the NPVs of the two​ projects? c. Why do IRR and NPV rank the two projects​ differently?
Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7...
Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7 MACRS Depreciation Rate ?14.29% ?24.49% ?17.49% ?12.49% ?8.93% ?8.92% ?8.93% ?4.46% Massive? Amusements, an owner of theme? parks, invests $ 60 million to build a roller coaster. This can be depreciated using the MACRS schedule shown above. How much less is the depreciation tax shield for year 4 under MACRS depreciation than under? 7-year, straight-line? depreciation, if the tax rate is 35?%?
Reconstructed Operating Statement Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Year...
Reconstructed Operating Statement Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7 Potential Gross Rent $457,200.00 $466,572.60 $476,137.34 $485,898.15 $495,859.07 $506,024.18 $516,397.67 $526,983.82 Allowance for Vacancies: Less $27,432.00 $27,432.00 $27,432.00 $27,432.00 $27,432.00 $27,432.00 $27,432.00 $27,432.00 Other Income $34,000.00 $34,697.00 $35,408.29 $36,134.16 $36,874.91 $37,630.84 $38,402.28 $39,189.52 Effective Gross Income $463,768.00 $473,837.60 $484,113.63 $494,600.31 $505,301.97 $516,223.02 $527,367.95 $538,741.35 Less: Less: Less: Less: Less: Less: Less: Less: Property Tax $85,039.00 $85,039.00 $85,039.00 $93,543.00 $93,543.00 $93,543.00 $93,543.00...
year 0 year 1 year 2 year 3 year 4 cashflow for S -100 40 50...
year 0 year 1 year 2 year 3 year 4 cashflow for S -100 40 50 30 30 cashflow for L -100 10 10 50 90 If the company's cost of capital is 5% and the decision is made by choosing the project with the higher IRR, how much value will be forgone? a. $4.01 b. $20.80 c. $29.89 d. $1.79 e. $12.45
Year 0 Year 1 Year 2 Year 3 Year 4 Revenue 120000 440000 440000 330000 Cost...
Year 0 Year 1 Year 2 Year 3 Year 4 Revenue 120000 440000 440000 330000 Cost of Goods Sold -60000 -220000 -220000 165000 Gross Profit 60000 220000 220000 165000 Selling, General and Admin -7000 -7000 -7000 -7000 Depreciation -80000 -80000 -80000 -80000 EBIT -27000 133000 133000 78000 Income tax (35%) 9450 -46550 -46550 -27300 Incremental Earnings -36450 86450 86450 50700 Capital Purchaes -280,000 Change to NWC -5,000 -5,000 -5,000 -5,000 A garage is installing a new​ "bubble-wash" car wash. It...
Given the year –by- year home run data for Brady Anderson: 1 0 1 4 3...
Given the year –by- year home run data for Brady Anderson: 1 0 1 4 3 2 21 13 12 16 50 18 18 24 19 8 1 Use Excel or Mathematica to answer the following questions: 1. Give the 10% (real world) trimmed mean.____________________ 2. Give the 20% (real world) trimmed mean.____________________ 3. Calculate the standard deviation_______________________________ 4. Calculate the Quartile values Q1 and Q3___________________________
Given the year –by- year home run data for Brady Anderson: 1 0 1 4 3...
Given the year –by- year home run data for Brady Anderson: 1 0 1 4 3 2 21 13 12 16 50 18 18 24 19 8 1 Use Excel or Mathematica to answer the following questions: a5. Find the IQR________________________________________ b6. Find the median_________________________ c7. Find the Maximum and Minimum values ____________________________ d8. Are there any outliers or extreme outliers? If so, what are they?_______________ e 9. Produce the boxplot (“box and whiskers”) in Mathematica and copy it here....
Year Cash Flow 0 $0 1 $250 2 $400 3 $500 4 $600 5 $600 What...
Year Cash Flow 0 $0 1 $250 2 $400 3 $500 4 $600 5 $600 What is the present (Year 0) value if the opportunity cost (discount) rate is 10 percent? Add an outflow (or cost) of $1,000 at Year 0. What is the present value (or net present value) of the stream?
In year 0, Longworth Partnership purchased a machine for $57,250 to use in its business. In...
In year 0, Longworth Partnership purchased a machine for $57,250 to use in its business. In year 3, Longworth sold the machine for $44,300. Between the date of the purchase and the date of the sale, Longworth depreciated the machine by $24,900. (Loss amounts should be indicated by a minus sign. Leave no answer blank. Enter zero if applicable.) a. What is the amount and character of the gain (loss) Longworth will recognize on the sale? Description Amount Total Gain/(Loss)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT