Search
 
SCRIPT & CODE EXAMPLE
 

CPP

leap year c++

#include <iostream>
using namespace std;

int main() {

  int year;

  cout << "Enter a year: ";
  cin >> year;

  // if year is divisible by 4 AND not divisible by 100
  // OR if year is divisible by 400
  // then it is a leap year
  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    cout << year << " is a leap year.";
  }
  else {
    cout << year << " is not a leap year.";
  }

  return 0;
}
Comment

c++ Program to check if a given year is leap year

// C++ program to check if a given
// year is leap year or not
#include <bits/stdc++.h>
using namespace std;
 
bool checkYear(int year)
{
    // If a year is multiple of 400,
    // then it is a leap year
    if (year % 400 == 0)
        return true;
 
    // Else If a year is multiple of 100,
    // then it is not a leap year
    if (year % 100 == 0)
        return false;
 
    // Else If a year is multiple of 4,
    // then it is a leap year
    if (year % 4 == 0)
        return true;
    return false;
}
 
// Driver code
int main()
{
    int year = 2000;
 
    checkYear(year) ? cout << "Leap Year":
                      cout << "Not a Leap Year";
    return 0;
}
 
// This is code is contributed
// by rathbhupendra
Comment

PREVIOUS NEXT
Code Example
Cpp :: compile cpp with specific version 
Cpp :: eosio multi index secondary index 
Cpp :: c++ text formatting 
Cpp :: c++ vector pop first element 
Cpp :: how to make sure the user inputs a int and not anything else c++ 
Cpp :: c++ fill array with 0 
Cpp :: compute the average of an array c++ 
Cpp :: c++ pause 
Cpp :: c++ celsius to fahrenheit 
Cpp :: find all occurrences of a substring in a string c++ 
Cpp :: multiply two Mat in c++ element per element 
Cpp :: how to use dec in C++ 
Cpp :: shuffle elements c++ 
Cpp :: c++ save typeid 
Cpp :: perulangan c++ 
Cpp :: assign a struct to another c++ 
Cpp :: Return multiple values from a function using pointers 
Cpp :: max three values c++ 
Cpp :: initialize all elements of vector to 0 c++ 
Cpp :: c++ file to string 
Cpp :: C++ Area of a Rectangle 
Cpp :: how to clear screen in C++ console 
Cpp :: c++ loop through array 
Cpp :: findung the mode in c++ 
Cpp :: how to make a n*n 2d dynamic array in c++ 
Cpp :: apply pca to dataframe 
Cpp :: c++ swapping two numbers 
Cpp :: difference between lower and upper bound 
Cpp :: how to make a random number in c++ 
Cpp :: copy a part of a vector in another in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =