Skip to main content

Posts

Check a number is odd or even without modulus operator

Codebeautify.org Text to HTML Converter 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
Recent posts

Why Isn't 1 a Prime Number?

The confusion begins with this definition a person might give of “prime”: a prime number is a positive whole number that is only divisible by 1 and itself . The number 1 is divisible by 1, and it’s divisible by itself. But itself and 1 are not two distinct factors. Is 1 prime or not? When I write the definition of prime in an article, I try to remove that ambiguity by saying a prime number has exactly two distinct factors, 1 and itself, or that a prime is a whole number greater than 1 that is only divisible by 1 and itself. But why go to those lengths to exclude 1? My mathematical training taught me that the good reason for 1 not being considered prime is the fundamental theorem of arithmetic, which states that every number can be written as a product of primes in exactly one way. If 1 were prime, we would lose that uniqueness. We could write 2 as 1×2, or 1×1×2, or 1 594827 ×2. Excluding 1 from the primes smooths that out. My original plan of how this article w

room-how-to-check-whether-row-exists

Use EXISTS , and return true false if you want to check some specific row and some condition , do this trick Query("SELECT EXISTS(SELECT * FROM tableName WHERE id = :id)") fun isRowIsExist(id : Int) : Boolean or simple use this    @Query("SELECT EXISTS(SELECT * FROM tableName)")    fun isExists(): Boolean

The world we live in

5 best meme generator apps for Android!

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