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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...