Find largest number using nesting and member function

                      Program to find Largest Number

  1. Code to find the largest of two number :-

#include<iostream.h>
#include<conio.h>
class largest
{
int no.1, no.2;
public:
void input()
{
cout<<"Enter two no. : \n ";
cin>>no.1>>no.2;
}
void large()
{
if(no.1>no.2)
{
cout<<no.1<<" is the largest number";
}
else
{
cout<<no.2<<" is the largest number";
}
};
void output()
{
large();
}
};
void main()
{
clrscr();
largest N1;
N1.input();
N1.output();
getch();
}


Output to find the largest of two number :-

Enter two no. :
10
20
20 is the largest no.


   2. Code to find the Largest of three numbers :-


#include<iostream>
#include<conio.h>
using namespace std;
class largest
{
int no.1, no.2, no.3;
public:
void input()
{
cout<<"Enter three no. : \n";
cin>>no.1>>no.2>>no.3;
}
void large()
{
cout<<"Entered numbers"<<"\n"<<"no.1:"<<no.1<<"\n"<<"no.2:"<<no.2<<"\n"<<"no.3:"<<no.3<<"\n";
if(no.1>no.2)
{
if(no.1>no.3)
{
    cout<<no.1<<" is the largest number";
    }
    else
    {
    cout<<no.2<<" is the largest number";
    }
    }
    else
    {
    if(no.2>no.3)
    {
    cout<<no.2<<"is the largest number";
}
else
{
cout<<no.3<<"is the largest number";
}
}
};
void output()
{
input();
large();
}
};
main()
{
largest N1;
N1.output();
getch();
}



Output of find the Largest of three numbers :-


Enter three no.
3
6
9
Entered numbers
no.1:3
no.2:6
no.3:9
9 is the largest number


Note:-

If you use turboc++ then you use this code,
if you use dev c++ the you use that header file and copy whole code

#include<iostream>
#include<conio.h>
using namespace std;
class largest..........
and copy whole code which is written above the note.

Comments

  1. Hii, Aditya
    This coding blog is very useful for me
    Thank you for this coding

    ReplyDelete
  2. Hii, Aditya
    Nice blog and this is helpful for my coding
    Thank you

    ReplyDelete

Post a Comment

Popular posts from this blog

Addition of two matrix using Array

Multiplication of matrix using Array

Addition of two no. using Class