Find largest number using nesting and member function
Program to find Largest Number
- 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();
}
#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
Hii, Aditya
ReplyDeleteThis coding blog is very useful for me
Thank you for this coding
Hii, Aditya
ReplyDeleteNice blog and this is helpful for my coding
Thank you