0
Hey guys , i got a problem in my code C++, cant get whats wrong, maybe somebody understands what requires to add?
this is my task “find the biggest difference between two elements in two arrays” https://code.sololearn.com/cX6V6uHE11rr/?ref=app
10 Respuestas
+ 3
I'm guessing you want the greatest difference between an element from 1 array to an element from the second array. I.E. the difference between the lowest element from one of the arrays and the largest element of the other.
You can get the difference as a positive value all the time by getting its absolute value. So if the element from array 1 is lower than the element from array 2 the difference is still positive. I.E. 4 - 96 = -92 and |-92| = 92.
Initially set the difference to the abs() of arr1[0] - arr2[0]. You can then loop over the remaining elements of arr2 checking if the abs() difference of arr1[0] - arr2[j] is greater than the current value of dif, setting the max() of the two back to dif.
When you reach the last element in the 2nd array set the value of j back to 0 and increment i by 1 and repeat the process this way until all elements of both arrays have been compared.
Example:
https://code.sololearn.com/cdfIH6O75PwB/?ref=app
+ 1
Here are some tips (not the solution):
Line 15, what if the result of the expression arr1[i] - arr2[j] is a negative number?
Line 17, this is the error you receive: arr1[0] - arr2[0] is not l-value. To fix it, create a variable and assign it the value of the expression you wrote.
yourVariable = arr1[0] - arr2[0];
Line 19, what exactly are you trying to do here?
+ 1
I think this might help
+ 1
Quanti I think he wants to find the difference between the numbers
+ 1
thanks a lot for you guys for help,ChaoticDawg it works thank you
+ 1
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x,k=0;
cin>>x;
if((x>=0) && (x<=5)){
double f1 = -log(x - 1 / x);
double a = 1;
k++;
a *= 1 / pow(x * k, k);
}
double f2 = 1 / pow(x * k, k);
printf("%4.2f %12.4f %12.4f\n", x, f1, f2);
return 0;
}
I did my best but i couldn't solve ..😣
0
In 19 line I added my max difference to a varible for a ensuing printing
0
in line 17 ,i did not want to do a comparison,i did a appropriation
0
thanks a lot for you try