Introduction to programming in c include using namespace std
Introduction to programming in c++
#include<iostream>
using namespace std;
int main() {
Puzzle: Write a version of the recursive even function that works on both positive and negative numbers. That is, it should return true for 0, 2, -2, 4, -4, etc. and false for 1, -1, 3, -3, etc.
bool even(int n) {
Solution
#include <iostream>
using namespace std;
//function to check the given number is even or odd
bool even(int n){
//if number is divisible by 2 i.e even return true
if(n%2==0)
return true;
//else return false
else
return false;
}
int main()
{int n;//variable for storing number entered by the user
//asking the user to enter the number
cout << \"Enter the integer \" << endl;
cin>>n;//store the entered number in n
n=abs(n);//calling absolute function to convert negative number into positive
if(even(n))//calling even function
cout<<\"The entered number is an even number \"<<endl;
else
cout<<\"The entered number is a odd number \"<<endl;
return 0;
}
********OUTPUT*****
Enter the integer
-34
The entered number is an even number
********OUTPUT*****
Note:In case of any doubt please ask the question,thanks.
