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 AnswersNew Answer
Oh man. And I've delete my Version, after David came with his. But now you both don't got it 😞
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.
Now look at this https://code.sololearn.com/cwGL6S9XyhxV/?ref=app
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
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..
Davide thank u so much ....
yess Thomas thank u so much to u too....
Yes we got it😄
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
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
Davide but output is not proper
__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
i mean to say values of min and max...
__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 🤗🤗🤗
I will try it one more time.
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.
2 test cases? Put it in a loop and it will do more than 42 test cases.
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 😌
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.