+ 1

How to find the biggest negative number between several numbers given in the input

Ok sooo it’s really not that difficult but I wanted to know how I should write a Cpp code ( that only uses •if• loop ) to show the biggest negative num between 5 nums from input , (And it’s important to *only* have the if loop , and not any *for* or any other loop .) I feel codupid :/

4th May 2020, 3:46 PM
Whiteout
Whiteout - avatar
4 Réponses
+ 4
Whiteout you are going to have to try yourself. We are not going to do your homework for you. Some pointers, the biggest negative number is the smallest number. The thing that you call an if loop, is most probably better known as recursion. If you are not going to respond to the request for your own try, we will have to delete this question. Looking forward to see your try.
4th May 2020, 5:06 PM
Louis
Louis - avatar
+ 2
Hi a cab show you how to solve this problem without for loops , you can only use STL algorithms, and have in input as much numbers as you want 🙂🙂
4th May 2020, 6:00 PM
꧁༒☬Bad☬Boy☬༒꧂
꧁༒☬Bad☬Boy☬༒꧂ - avatar
+ 1
#include <iostream> using namespace std; int main() { int n1,n2,n3,n4,n5; cin>>n1; cin>>n2; cin>>n3; cin>>n4; cin>>n5; if((n1>n2)&&(n1>n3)&&(n1>n4)&&(n1>n5)) cout<<"The Greatest negative numner : "<<n1; if((n2>n1)&&(n2>n3)&&(n2>n4)&&(n2>n5)) cout<<"The Greatest negative numner : "<<n2; if((n3>n1)&&(n3>n2)&&(n3>n4)&&(n3>n5)) cout<<"The Greatest negative numner : "<<n3; if((n4>n1)&&(n4>n2)&&(n4>n3)&&(n4>n5)) cout<<"The Greatest negative numner : "<<n4; if((n5>n1)&&(n5>n2)&&(n5>n3)&&(n1>n4)) cout<<"The Greatest negative numner : "<<n5; return 0; }
4th May 2020, 5:27 PM
Dasarath Singh
+ 1
https://code.sololearn.com/ckqIa43GiA2P/?ref=app Try this and look how it works 🙂 I hope it will help you
4th May 2020, 6:10 PM
꧁༒☬Bad☬Boy☬༒꧂
꧁༒☬Bad☬Boy☬༒꧂ - avatar