0
Finding second smallest number out of 3 unknown numbers in c++
my code- (please explain where am i wrong) #include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a<=b && b<=c && a<=c) cout<<b; else if (b<=c && c<=a) cout<<c; else cout<<a; return 0; }
8 Respuestas
+ 7
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
{
cout << "Largest number: " << n1;
}
if(n2 >= n1 && n2 >= n3)
{
cout << "Largest number: " << n2;
}
if(n3 >= n1 && n3 >= n2) {
cout << "Largest number: " << n3;
}
+ 6
Bartas Dausynas U can use equality operator for this situation
yes it should be print two number but u can use exception handling in this case
0
If you add a small if before the first if.
Like
if(c<a) {
int tmp = c;
c = a;
a = tmp;
}
The problem you have that if c is smaller than a you first if dosnt worl correctly
0
Navneet Chauhan think,
if (c<=b && b<=a)
what should be the answer?🤔🤔
0
For kth smallest using std::priority_queue
https://code.sololearn.com/cXtA80Pq8xXK/#cpp
For smallest using std::min_element
https://code.sololearn.com/cVljOO5Y38lC/#