15,610,088 members
See more:
Create a single-dimensional array X with integers in the range [600;700]. The number of array elements is determined by the user. Calculate and save the value in Y array according to the formula y=√((x+4)/(x-sin(5x))+) ∛(x+4) . Display two arrays on the console as a table.
X and Y with up to 4 digits after fractional partitioner.
Find the value of X at which Y is the maximum and display X / Y on the console.

What I have tried:

i tried but cant understand algorithm
Posted
Updated 16-May-22 2:53am
v3

## Solution 1

Quote:

Quote:
i tried but cant understand algorithm

This is not an algorithm, this is requirement.
As programmer, your job is to create the algorithm.
If you really fo not understand the requirement, you need to talk with your teacher.

Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
Program Development by Stepwise Refinement[^]

CPallini 16-May-22 5:22am
5.
Patrice T 16-May-22 5:43am
Thank you

## Solution 2

The formula is as specified in the question. The Math Class (System) | Microsoft Docs[^] contains methods for square and cube roots and sin, so the calculations should be fairly easy to do.

The number of elements is, as specified, selected by the user. So the first thing to do is ask the user how many values they wish to calculate with. The answer can be used to allocate the two arrays, X and Y. Then ask the user to enter the individual numbers, checking that they are in the range [600..700].

You then apply the formula to each value of X, saving the result in the corresponding element of Y. And finally display the relevant answers.

v2
CPallini 16-May-22 5:22am
5.
Richard MacCutchan 16-May-22 5:27am
Thanks (again).

## Solution 3

The first requirement is to create and populate an array with `N` (provided by the user) values in the `[600..700]` range.
You may choose how to populate such an array. One alternative is constantly increasing values, e.g.
C#
```const double XMin=600.0;
const double XMax=700.0;
double [] x = new double[N];
for (int n=0; n<N; ++n)
{
x[n] = XMin + n*(XMax-XMin)/(N-1);
}
```
Now, you have the `x` array.
In order to have the corresponding `y` one, compute the given formula for every `x` item, keeping track of the maximum value.
The final step, it is just matter of formatting.

Patrice T 16-May-22 5:44am
+5
CPallini 16-May-22 9:11am
Thank you.
George Swan 16-May-22 10:32am
Should not the X array be an int array? The question says, Create a single-dimensional array X with integers
CPallini 16-May-22 10:42am
You are probably right. Anyway, it is difficult to populate the array if the number of items is choosen by the user (you have to introduce duplicates).
George Swan 16-May-22 11:59am
My approach to generating the X array would be something like this
```           Random random = new Random();
//range 600 to 700 inclusive
int[] choices = Enumerable.Range(600, 101).ToArray();
// Fisher–Yates shuffle method
int i = choices.Length - 1;
while (i > 0)
{
//k is chosen from a decreasing number of elements
int k = random.Next(i + 1);//range is 0-i inclusive
var temp = choices[i];
choices[i] = choices[k];
choices[k] = temp;
i--;
}
int N = 6;//provided by user
int[] X = new int[N];
Array.Copy(choices, X, X.Length);
```