Given a number, check whether it is even or odd.
Method 1: Using Loop.
The idea is to start with a boolean flag variable as true and switch it n times. If flag variable gets original value (which is true) back, then n is even. Else n is false.
Below is the implementation of this idea.
C++
// A simple C++ program to check for
// even or odd
#include
using namespace std;
// Returns true if n is even, else odd
bool isEven(int n)
{
bool isEven = true;
for (int i=1; i <= n; i++)
isEven = !isEven;
return isEven;
}
// Driver code
int main()
{
int n = 101;
isEven(n) ? cout << "Even" : cout << "Odd";
return 0;
}
Java
// A simple Java program to
// check for even or odd
class GFG {
// Returns true if n
// is even, else odd
static boolean isEven(int n)
{
boolean isEven = true;
for (int i = 1; i <= n; i++)
isEven = !isEven;
return isEven;
}
// Driver Code
public static void main(String args[])
{
int n = 101;
if(isEven(n))
System.out.println("Even");
else
System.out.println("Odd");
}
}
Examples :
Input: n = 11
Output: Odd
Input: n = 10
Output: Even
Finding good meme generator apps can be hard. There are a ton of them out there and most of them are pretty bad. Memes are awesome things that are useful and hilarious everywhere which means you should have a good meme generator app to help out. Please note that these things pop up and go down all the time. The ones on the list should be around for a while, though! Check out the best meme generator apps for Android! GATM Meme Generator Mematic Memedroid Meme Generator by ZomboDroid iFunny, Tumblr, Giphy, etc Bonus: Web browsers GATM Meme Generator Price: Free / $1.95 GATM Meme Generator is one of the few good meme generator apps with semi-frequent updates. It includes a gallery of images or you can bring your own images to meme. The app also comes with no watermark, relatively recent meme templates, and relatively decent stability. It undergoes the occasional redesign, but most of its functionality remains intact. The free version contains ads. The pro version goes for $1.95...
Comments
Post a Comment
Thanks For your comment.