CS10L - Laboratory Exercise #3 - 2nd Term - 20122013

Problem Statement: All years that are evenly divisible by 400 or are evenly divisible by four and not evenly divisible by 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 by 100, the year 1988 was also a leap year. Using this information, write a C++ program that accepts the year as user input, determine if the year is a leap year, and displays an appropriate message that tells the user if the entered year is or is not a leap year.

CODE:
 
/**
    Laboratory Exercise #3
    CS10-B5
   
    @author Red Berroy
*/
#include <iostream.h>
int main()
{    
 int year,leap;
 //Variable names
 cout<<"Enter a year: ";
 cin>>year ;
 //Enter year
 leap=year%4;     
 if (leap==0)
 //Formula
{                         
 cout<<year<<" is A LEAP YEAR."<<endl; 
 //Displays a leap year result 
}            
 else            
{                
 cout<<year<<" is NOT A LEAP YEAR."<<endl;
 //Displays not a leap year result
}      
 return 0;
}

0 comments:

Post a Comment

ADVERTISEMENT