Question

In: Computer Science

All years that are evenly divisible by 400 or are evenly divisible by four and not...

All years that are evenly divisible by 400 or are evenly divisible by four and not evenly divisible 100 are leap years. For example, since 1600 is evenly divisible by 400, the year 1600 was a leap year. Similarly, since 1988 is evenly divisible by four but not 100, the year 1988 was also a leap year. Using this information, write a C++ program that accepts the year as user input, determines if the year is a leap year, and displays an appropriate message that tells the user whether the entered year is or is not a leap year.

Solutions

Expert Solution

C++ Program

#include <iostream>

using namespace std;
bool LeapYear(int year){//function LeapYear
if(year%400==0)
return true;
if(year%4==0 && year%100!=0)
return true;

return false;
}
int main()//main
{
int year;
cout<<"Enter Year: ";
cin>>year;
  
bool flag=LeapYear(year);//call function LeapYear
  
if(flag==true)
cout<<year<<" is a Leap Year";
else
cout<<year<<" is not a Leap Year";
return 0;
}

OUTPUT


Related Solutions

isPrime Function. A prime number is a number that is only evenly divisible by itself and...
isPrime Function. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. The...
A prime number is an integer greater than 1 that is evenly divisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Create a PrimeNumber application that prompts the user for a number and then displays a message indicating whether the number is prime or not. Hint: The % operator can be used to determine if one number is evenly divisible by another. Java
A prime number is an integer greater than 1 that is evenly divisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Create a PrimeNumber application that prompts the user for a number and then displays a message indicating whether the number is prime or not. Hint: The % operator can be used to determine if one number is evenly divisible by another. b) Modify the...
10. Write a for loop which will print every number evenly divisible by 13 between 1...
10. Write a for loop which will print every number evenly divisible by 13 between 1 and 100, inclusive. Your loop will only increment by 1 each loop so you need an if test to see if each number should be printed. Put each number output on the same line, 1 space apart. 11. Write a while loop which will prompt the user for a number and accept their input and then display this message (assuming number input is 3)...
For all the baseball fans out there: Assuming that two teams are evenly matched in the...
For all the baseball fans out there: Assuming that two teams are evenly matched in the World Series (a championship series of at most 7 games; the first team to win 4 games wins the Series) so that the probability of each team winning each game is 50%, and assuming each game is independent of each other game, what is the probability that the Series will be won in exactly 4 games? 5? 6? that the Series goes to game...
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
Let L1 be the language of the binary representations of all positive integers divisible by 4....
Let L1 be the language of the binary representations of all positive integers divisible by 4. Let L2 be the language of the binary representations of all positive integers not divisible by 4. None of the elements of these languages have leading zeroes. a) Write a regular expression denoting L1. b) Write a regular expression denoting L2. c) a) Draw a state diagram (= deterministic finite state automaton) with as few states as possible which recognizes L1. This state diagram...
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
You will receive three cash flows:(i) $400, today(ii) $1,000, four years from today(iii) $500, eight years...
You will receive three cash flows:(i) $400, today(ii) $1,000, four years from today(iii) $500, eight years from today At an annual effective interest rate i, the combined present value of these three cash flows is $1505.80. At the same annual effective rate i, find the accumulated value of $60 after three years.
Consider all positive integers less than 100. Find the number of integers divisible by 3 or...
Consider all positive integers less than 100. Find the number of integers divisible by 3 or 5? Consider strings formed from the 26 English letters. How many strings are there of length 5? How many ways are there to arrange the letters `a',`b', `c', `d', and `e' such that `a' is not immediately followed by`e' (no repeats since it is an arrangement)?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT