Pages

Friday, April 4, 2025

Check largest of 3 numbers in functions in C++

 #include<iostream>

using namespace std;

// finds the largest of 3 numbers

void largestNum(int a, int b, int c) {
    if(a > b && a > c) {
        cout << a << " : A is greater than B and C";
    } else if(b > a && b > c) {
        cout << b << " : B is greater than A and C";
    } else {
        cout << c << " : C is greater than B and A";
    }  
}

int main(){

    largestNum(12, 8, 6);

    return 0;
}

OUTPUT-
12 : A is greater than B and C

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...