Pages

Monday, March 31, 2025

Check odd or even in functions in C+++

 CASE 1- Odd Number


#include <iostream>

using namespace std;


int prod(int a, int b) {
    return a * b;
}

// even -> true; odd -> false
bool isEven(int n) {
    if(n % 2 == 0){
        return true;
    } else {
        return false;
    }
}

int main(){
     cout << isEven(19) << endl;

    return 0;
}

OUTPUT-

0
CASE 2- Even Number

Output- > 1

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...