What are the errors in this program??program is about printing minimum and maximum numbers...in c | SoloLearn: Learn to code for FREE!

+1

What are the errors in this program??program is about printing minimum and maximum numbers...in c

https://code.sololearn.com/cSjh1TGG9vKq/?ref=app here is the code ... i have to print min and max nos. there should be 2 test cases and it should prints min ,max of both the cases.. but here is some error i can't understand.. take inputs as: 2 //no of test case(T) 6 //length of array(N) 3 1 4 6 2 7 //first test case 6 //length of array(N) 0 0 0 0 0 0 //second test case **output should be: 1 7 0 0

10/17/2020 11:03:59 AM

__n

27 Answers

New Answer

+2

Oh man. And I've delete my Version, after David came with his. But now you both don't got it 😞

+2

Thomas I think that the problem is the poor variable naming that creates misunderstanding. T is supposed to store the number of tests cases, and N the number of integers for a particular test case. You considered only one test case and used the first input T to store the number of integers for that test case. When I tried your program, the first input I gave was for the number of test and the second for the number of integers N. But you used the second input as one of integers, so I thought you were printing N and not one of the six integers.

+1

Now look at this https://code.sololearn.com/cwGL6S9XyhxV/?ref=app

+1

All right since you wanted a program that work with numbers and spaces, scanf is definitely easier to implement than fgets. So I took Thomas code and made few changes. Here is your program: https://code.sololearn.com/c1mO4cw4vBxN/?ref=app

+1

Thomas your code is right...but there are 2 cases..so it should print min ,max of both the test cases..as i mentioned in my question..

+1

Davide thank u so much ....

+1

yess Thomas thank u so much to u too....

+1

Yes we got it😄

+1

Have a look at this. I have added number of test cases. And changed some data types from int to long int for Bigger numbers. Idk if this is what you need. But it's all I can do. https://code.sololearn.com/cwGL6S9XyhxV/?ref=app

+1

Thomas thanks

0

I modified it to make it work, but I don't know wether some of the changes were necessary, like using fgets instead of scanf or avoiding using VLA. However I know that they are best practices, so I don't bother too much on knowing why the code doesn't work without these changes. Here is the code: https://code.sololearn.com/cySTtJK8urhc/?ref=app

0

Davide but output is not proper

0

__n Yes it is. I just added "min: " "max: " and newlines to the final printf for more clarity. You can remove them and get the desired format

0

i mean to say values of min and max...

0

__n oh maybe the problem is that you put a space between the 6 numbers. Since in your example you used only one-digit numbers I didn't care about spaces. Change any occurrence of A[i] with A[i*2-1] and it works even with a space between numbers. But only for one space and one-digit numbers. If you want to make it work for bigger numbers you need to use strtok() to extrapolate the numbers stored into the array. edit: actually changing A[i*2-1] is not enough, you need to also double the SIZE and the exit condition of the inner loop. I could do it for you, but you need to get your hands dirty as well. Try to make it work in the way you want and ask help only if you get stuck. Send you concentration hugs to help concentrate while coding 🤗🤗🤗

0

I will try it one more time.

0

What about this spaces? This works how it is. First Input = number of values then enter Then the values, each in a new line with enter. After last value submit! And it works with all values you want.

0

2 test cases? Put it in a loop and it will do more than 42 test cases.

0

Thomas your program doesn't work properly. The 6 in the output is the one stored in N, not the one that is the biggest number among the six integers. Anyway we finally solved this problem all together. Now forget about it and be happy 😌

0

Hmm, the output variables are named "min" and "max". Could you show me the line where one of them becomes "N"? Maybe I haven't seen it.