There is a Cauchy inequality. The user sets the value n . Everything seems to be easy, but I can’t figure out how to write in such a way that the number a in the inequality changes from the entered n ( a is randomly obtained numbers).

Cauchy inequality

  • perhaps it is worth using arrays. and what function is it? - diraria
  • @diraria function in the photo, I am sure that there is no way without arrays, but I have no idea how to do it. even if in words explain, I will already be very grateful) - Hate Fate
  • the photo is not a function but an inequality) the function has parameters and a return value. Tell me, please, what does the function accept and what should it return? - diraria
  • one
    This inequality is always true. What should the program do? - user239133
  • @diraria is your truth) this is only part of the task. In the end, everything works like this: for the entered number "n", you need to check this statement (which is on the photo) in 1000 different sets. The numbers "a" are randomly generated from 0 to 100. As a result, you need to display all the sets where the difference between the left and right sides of the inequality is less than 5%. - Hate Fate

2 answers 2

 int a; // рандомные числа int aIncr = 0; // здесь будет результат сложения всех "a" int aMult = 1; // здесь будет результат умножения всех "a" // Где-то получено значение "n" for(int i = 0; i < n; i++){ a = (рандомное число); aIncr += a; aMult *= a; } 

It remains to replace the expressions in brackets with the variables "aIncr" and "aMult"

    As I understand it, the question is how to work with arrays.

    • You can create an array of a certain size like this:

       int[] array = new int[размер_массива]; 

      the resulting array will be filled with zeros

    • You can refer to the element by index (array indices are numbers from zero to размер_массива - 1 ):

       array[индекс] 
    • You can run through the entire array using the for loop:

       for (int i = 0; i < array.length; ++i) ... 

      For example, this is how you can get the sum of all the elements of an array:

       int sum = 0; for (int i = 0; i < array.length; ++i) sum += array[i]; 

      (by the way, here are some more ways to find the sum of the elements of an array )

    • Thanks for the information and help, as far as I understood, I need to do this: I find the sum divided by "n" and the product offered by 1 / n, I compare them to the difference of inequality. And I insert all this code into a loop that will be executed 1000 times. And already from these 1000 cases I choose those that suit me (the difference is less than 5%). - Hate Fate