Advertisements
Advertisements
प्रश्न
Write a C++ program to find the smallest of five given integers using the min() function to return the smallest of five given integers.
कोड लेखन
Advertisements
उत्तर
#include
<iostream.4> int min 9int, cint, int, int, int);
main()
{
int a, b, c, d, c, small;
cout<<"Enter the five nos",
in>>a>>b>>c>>d>>c;
small = min(a, b, c, d, c);
cout<<in The smallest No is
= "<<small;
return(0)
}
int min (int nt, inf n2,
in n3, int n4, inf n5)
{
int low;
low = nt
if (n2<low)
low = n2;
if (n3<low)
low = n3;
if (n4<low)
low = n4;
if (n5<low)
low = n5;
return (low);
}
- The
min()function (from<algorithm>) compares two values and returns the smaller one. - Since
min()works with two values at a time, we nest the function calls to compare all five numbers. - The final result is stored in the variable
smallest.
Example
Input: 10 25 3 40 18
Output: Smallest number is: 3
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2024-2025 (July) Official Board Paper
