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

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