9. Program that inputs a year and display "Leap year" if it is a leap year otherwise displays "Not a leap year".

Chapter 5: 

Conditional Structures

Programming Exercise

Problem # 9:

A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 400. Write a program that inputs a year such as 1996, 1800 and 2010 and display "Leap year" if it is a leap year otherwise displays "Not a leap year".

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
    int year;
    cout<<"Enter a year:";
    cin>>year;
    if(year%4==0 && year%100!=0)
    cout<<"It is a leap year.";
    else if(year%100==0 && year%400==0)
    cout<<"It is a leap year.";
    else
    cout<<"It is not a leap year.";
    return 0;
}


Let me know in the comment section if you have any question.

Previous Post:
8. Program that inputs a value and type of conversion. The program should then output the value after conversion.

Comments