Arrangement of Numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Arrangement of Numbers

I am a beginner of C++ program, and today is my second day of learning. There is a question in my assignment which said"please arrange and output four random numbers from smallest to biggest. And four numbers are between 0 and 10^10." Actually I design a program which is able to meet the request, but when I uploaded to the other test system, it told me it's a wrong answer. I wanna know if my program is incorrect or there are some conditions I've never consider. MY PROGRAM : https://code.sololearn.com/cwuLl33pqrdA/#cpp THANK YOU FOR YOUR HELP!!!!

22nd Aug 2019, 1:48 PM
莊向軒
莊向軒 - avatar
4 Answers
+ 2
int can store max 2^32. If input is 10^10, then size of int variable is not sufficient...!!! Normally, 1st check test systems do is range check - . i. e. How SW behaves when minimum and maximum values are given. In your case it is 0 and 10^10. Hope this helps...!!!
22nd Aug 2019, 2:38 PM
Kuri
Kuri - avatar
+ 5
Your code does not work properly because you have a misunderstand in logical operators if(a>b&&c&&d) it will not compare a with b then with c then with d it will compare just with b then take the result and c and d you did mean if(a>b&&a>c&&a>d) in C++ every non zero value is true and just 0 is false so consider the following example in your comparison and mine a=4,b=3,c=2,d=6 if(a>b&&c&&d) in values if(4>3&&2&&6) if(1&&non zero) if(1) so it is true although a is smaller than d if(4>3&&4>2&&4>6) if(1&&1&&0) if(0) it is false and works properly
22nd Aug 2019, 4:31 PM
ABADA S
ABADA S - avatar
+ 1
Hi.. Modified some syntax in condition by putting additional brackets. Variable type changed from int to long long int. Check if your test system passes now. Same problem can be realized in more efficient way... https://code.sololearn.com/cRGAoPl6dVXd/?ref=app Hope this helps...!!!
24th Aug 2019, 7:36 AM
Kuri
Kuri - avatar
0
Really appreciate for both of your passionate helps. Unfortunately, I am still not pass it although my codes are proper and correct. I'll keep looking for where the points are. THANK YOU~~~
24th Aug 2019, 6:52 AM
莊向軒
莊向軒 - avatar