C++ program to input two integers that return the smallest one.
# include "iostream.h"
# include "conio.h"
int min(int a, int b)
{
if (a< b )
return(a);
else
return(b);
}
char min(char a, char b)
{
if (a< b )
return(a);
else
return(b);
}
double min(double a, double b)
{
if (a< b )
return(a);
else
return(b);
}
void main()
{
int n, n1;
char ch, ch1;
double d, d1;
clrscr();
cout << "Enter two integers ";
cin >> n >> n1;
cout << "Enter two characters ";
cin >> ch >> ch1;
cout << "Enter two double precision quantity ";
cin >> d >> d1;
cout << "\nMinimum of two integer "<< min(n,n1);
cout << "\nMinimum of two characters "<< min(ch,ch1);
cout << "\nMinimum of two double precision quantity "<< min(d,d1);
}
step by step explaination:
1.Header file "iostream.h" is used to defyning the function cin and cout.
2.Header file "conio.h" is used to defying the printf and scanf function.
3.If is a "conditional statement" that is used to apply the condition.
4.else is also a "conditional statement" it is used in case of failing the if statement.
5.main is also a void type function and it is worked untill the curley brackets.
No comments:
Post a Comment