0
CODE not working
i honestly dont se any issues here,why its not scanning anything from me? please run it on a ide with terminal https://code.sololearn.com/ccV3tfuD9Rbi Your job in this problem is to read a number that is a line of an array, an uppercase character, indicating the operation to be performed and all elements of a bidimentional array M[12][12]. Then, you have to calculate and print the sum or average of all elements within the green area according to the case. The following figure illustrates the case when is entered the number 2 to the array line, showing all elements that must be considered in the operation.
13 ответов
+ 3
I changed the code to use random values for <array> elements. This is done solely to allow the code to be tested in Playground without worrying about input limits.
https://code.sololearn.com/cxd1E81H0KLr/?ref=app
0
Does variable <line> represent matrix size? I had to ask cause I see you ask for <line> input but the loop goes 12 x 12 times. What's the point of asking input for <line> when you run the loop 12 x 12 times?
0
No, it is variable <choose> that decides whether to sum or average. Please read my confirmation once again
0
*sigh* wish you had included that link in your original post so things can come clear earlier.
It's hard to test your code in Playground cause it needs 144 number input (12x12) and the input dialog limits input only 100 characters.
May I suggest, during this testing time, just fill the matrix with random data so that we can focus on analysing the averageline() and sumline() works?
Once testing is done, you can revert the code back to ask user for matrix data.
0
Have you tried to provide the inputs in the input text below code editor and choose "Text" opposed to "interactive console"?
From experience I have learned that a simulated interactive console is a menace LOL
0
Anik,
The first ones I see from your recent respond was ...
sumline() and avarageline() are defined as functions that returns a `double` value. But sumline() returns <sum> which is a float variable. And avarageline() doesn't return any value.
You can change both function's return type to float, and return <avarage> from avarageline().
0
try to make it work on a smaller array and paste debug messages into different parts of code to see which lines are being executed and which not
- 1
this is the line of which's values I'll count max or average..
if line is 2 then arr[2][j] will be summed
- 1
line determines which line elements to sum
- 1
i mean in onligdb on terminal this code is not even taking the inputs from me,also they are no working how its supposed to
- 1
i guess they wont take 144 inputs,thats why
- 1
#include<stdio.h>
double sumline (float arr[12][12], int L1)
{
float sum = 0;
for (int i = 0; i < 12; i++)
{
sum += arr[L1][i];
}
return sum;
}
double avarageline (float arr1[12][12],int L2)
{
float avarage = sumline (arr1, L2) / 12.00;
printf ("%.1lf\n",avarage);
}
int main ()
{
int line;
double array[12][12];
scanf ("%d", &line);
fflush(stdin);
char choose;
scanf ("%c",&choose);
fflush(stdin);
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 12; j++)
{
scanf ("%lf",&array[i][j]);
}
}
if (choose == 'S')
{
printf ("%.1lf\n",sumline (array,line));
}
else if (choose == 'A')
avarageline (array,line);
return 0;
}
from a standard point of view how would a very efficient programmer approach this problem and why it still gives me wrong answer....