We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
PROGRAM-10
AIM- Write a program to find the biggest of three number
using Friend Function.
THEORY- This C++ program uses a friend function to find
the largest of three numbers. The Numbers class stores the three integers, and the findLargest function, which is declared as friend of the class, has direct access to the class's private data members. The program prompts the user to input three numbers, then calculates and displays the largest of them.
CODE- #include <iostream>
using namespace std;
class Numbers {
private:
int num1, num2, num3;
public:
Numbers(int n1, int n2, int n3) {
num1 = n1;
num2 = n2;
num3 = n3;
friend int findLargest(Numbers);
};
int findLargest(Numbers n) {
int largest = n.num1;
if (n.num2 > largest) {
largest = n.num2;
if (n.num3 > largest) {
largest = n.num3;
return largest;
int main() {
int a, b, c;
cout << "Enter three numbers: ";
cin >> a >> b >> c;
Numbers obj(a, b, c);
int largest = findLargest(obj);
cout << "The largest number is: " << largest << endl;