Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Thursday, August 15, 2024

C++ program for inline function.

 Object: Write a C++ program to find the largest of three numbers using inline function.


Code:

#include <iostream>

using namespace std;

// Inline function to find the maximum of three numbers

inline int maxOfThree(int a, int b, int c) 

{

    return (a > b) ? (a > c ? a : c) : (b > c ? b : c);

}

int main() 

{

    int num1, num2, num3;

    // Input three numbers

    cout << "Enter three numbers: ";

    cin >> num1 >> num2 >> num3;

    // Find the largest number using the inline function

    int largest = maxOfThree(num1, num2, num3);

    // Output the largest number

    cout << "The largest number is: " << largest << endl;

    return 0;

}


Output: 




No comments:

Post a Comment