Answer to Question #305896 in C++ for Magisk

Question #305896

Instructions:




1. You are provided with the isLeapYear() function which is already declared and defined for you.



2. Your task is to ask the user for a year and then call the isLeapYear function to check whether the year is a leap year or not.



Input




1. Year to be checked




Output




If a certain year is a leap year, print "<INSERT_YEAR_HERE> is a leap year"



Otherwise, print "<INSERT_YEAR_HERE> is not a leap year"




Sample Output:



Enter·year:·2020



2020·is·a·leap·year




This is the given code:




#include <iostream>



using namespace std;




int isLeapYear(int);




int main(void) {



// TODO: Write your code here




return 0;



}




int isLeapYear(int n) {



if(



(n % 4 == 0 && n % 100 != 0) ||



(n % 100 == 0 && n % 400 == 0)



) {



return 1;



}




return 0;



}

1
Expert's answer
2022-03-04T04:04:44-0500
#include <iostream>
using namespace std;


int isLeapYear(int);


int isLeapYear(int n) 
{
	if((n % 4 == 0 && n % 100 != 0) || (n % 100 == 0 && n % 400 == 0)) 
	{
		return 1;
	}
	return 0;
}


int main(void) 
{
	// TODO: Write your code here
	int Yr,Flag=1;
	
	while(Flag)
	{
		cout<<"\n\tEnter a Year: "; cin>>Yr;
		if(isLeapYear(Yr)) 	cout<<"\n\t"<<Yr<<" is a leap year.";
		else				cout<<"\n\t"<<Yr<<" is not a leap year.";
		cout<<"\n\tPress 1 to continue or 0 to QUIT: "; cin>>Flag;		
	}
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog