In this problem, you will need to step through a large array to find how many va
ID: 3594285 • Letter: I
Question
In this problem, you will need to step through a large array to find how many value fit a given condition. This is similar to a homework problem. You are free to reuse any code you have written yourself. This problem is longer than the others, so you may want to come back to it Problem statement Give the following array of float values, how many of the values, when squared, result in a value greater than .5? For example, the value of 0.80 when squared would be 0.64, which would count toward the total. Here is the list of values in a single array initializer float r [50010.99,-0.10,-0.86,0.38,0.73,1.00,0.66,0.53,0.64,-0.65,0.03,0.83,0.48,-0.32,-0.28,0.75,0.33,-0.80,- 0.48,0.47,-0.76,0.10,0.04,-0.89,0.19,0.11,-0.33,0.16,0.33,-0.08,0.17,0.68,-0.83, 0.66,0.06,0.90,0.66,0.07,0.43,0 29,0.42,-0.19,0.12,0.25,0.85,0.85,-0.00,0.18,-0.95,0.87,-0.35, -0.35, -0.04,-0.96,0.11,-0.84,0.15,-0.87,0.67,-0.17, 0.04,0,19,-0.49,0.56,0.15,0.92,0.46,-0.50,-0.02,0.24 , 0 . 79,-0.60,-0.96,0.27,0.65,-0.76,0.47,0,00,0.42 , 0 . 52,-0.13, -0.58,-0.48,-0.82,-0.54,0.97,-0.66,0.96,-0.90,-0.64,-0.20,0.49,0.55,0.30,0.06,-0.60,0.22,-0.14,0.25,-0.44,-0.90 0.40,-0.04,-0.51,-0.33,-0.04,-0.26,-0.86,-0.69,-0.49,-0.99,0.53,-0.07,-0.13,0.71,0.74,-0.15,-0.59,0.70,0.30,-0.2 3,-0.50,-0.21,-0.33,-0.85,-0.80,0.42 , 0 . 73,0.06,-0.33,-0.71,0.51,-0.94,0.60,-0.99,-0.27,-0.09,0.10,0.22 , 0 .23,0.60, 0.22,0.11,-0. 46,-0.91,-0.17,-0.72,0.29,0.59,0.98,-0.06,-0.30,-0.17,0.73,0.37,0.34,-0.71,-0.21,0.07,0.70,0.81,0.3 5,0.21,0.87,0.31,0.57,-0.05,-0.78,-0.34,-0.83,0.80,-0.73,0.74,-0.08,0.16,-0.81,-0.90,0.43,0.48,-0.96,0.77,-0.58,- 0.26,-0.05,-0.49,-0.53,-0.71,0.15,0.61,0.70,-0.15,0.41,0.41,-0.59,0.28,-0.28,-0.67,-0.41,-0.06,-0.01,-0.24,0.10, 0.61,-0.50,-0. 63,-0.23,-0.30,-0.18,-0.44,-0.47,-0.14,-0.32,0.31,0.96,0.98,-0.83,-0.22,-0.38,0.32,-0.61,-0.68,-0.4 8,-0.85,0.73,0.28,0.79,-0.55,0. 61,-0.62,0.74,-0.05,0.14,0.20,-0.08,0.99,0.56,-0.96,0.04,-0.61,-0.05,0.57,0.60,0.9 8,0.23,0.56,0.96,0.40,-0.31,-0.42,-0.28,0.08,-0.10,0.58 , 0 . 58,-0.02,0.14,0.37 , 0 . 43,-0.18 , 0 . 75,0.53 , 0 . 77,0.24,-0.2 7,0.04,0.23,-0.36,0.09,-0.73,0.03,-0.96,-0.81,-0.02,-0.98,0.42,-0.10,-0.67,0.17,0.59,0.26,-0.76,0.01,-0.49,0.83,- 0.41,0.49,0.04,0.96,0.28,0.86,0.71,-0.19,0.98,0.30,0.54,0.03,-0.47,-0.82,-0.53,0.16,0.56,-0.49,0.70,-0.45,-0.12, 0.48,0.80,0.56,-0.34,0.38,-0.17,-0.10,-0.60,0.34,-0.27,-0.01,-0.17,0.77,0.31,-0.89,0.98,0.38,0.28,0.96,-0.32,0.1 7,0.01,0.56,0.70,0.46,-0.28,0.26,-0.68,-0.22,-0.84,0.55,-0.74 , 0 . 95,0.12,-0.09,0.69,-0.71,0.82,-0.91,0.63,-0.10, 0.44,-0.18,0.01,0.10,-0.07,-0.01,-0.53,-0.79,-0.04,0.50,0.37,-0.70,0.06,0.07,-0.88,-0.86,-0.32,-0.56,-0.09,0.19,- 0.66,0.17,0.15,0.81,-0.56,0.19,-0.90,-0.40,0.28,0.73,0.50,0.07,-0.45,-0.49,-0.48,0.83,0.51,-0.01,-0.61,-0.19,-0.1 5,0.76,0.12,-0.74,0.19,0.23,-0.25,0.87,-0.98,0.66,0.41,-0.64,0.18,-0.44,-0.83,0.97,0.75,-0.37,-0.42,0.38,-0.63,- 0.93,-0.20,0.27,-0.06,0.32,0.10,-0.20,-0.34,0.50,0.61,0.51,0.61,0.08,0.77,-0.20,-0.34,-0.48,0.02,-0.32,-0.46,-0.5 7,0.40,-0.93,0.34,0.92,-0.61,0.44,-0.45,-0.03,0.18,0.27,0.39,0.98,-0.46,-0.67,0.65,1.00,0.48,-0.69,0.49,0.44,0.8 2,0.46,-0.48,0.95,-0.39,0.18,-0.18,0.98,-0.79,0.71,-0.24,0.61,-0.87,-0.89,0.89,-0.47,0.90,-0.56,0.49,0.08,0.71,0 24,0.41,-0.74,0.57,0.06,-0.39,0.06,0.37,-0.55,-0.15,0.54,0.91,0.37,0.84,-0.12,-0.09,0.01,-0.14,0.12,0.08,0.62,0.0 8,0.21,-0.92,-0.03,-0.91,0.98,0.77,0.94,0.41,0.48;Explanation / Answer
As you have not mentioned any language i will give you the idea that as we know sqrt (0.5)=0.707 approximately.
Traverse through the array set a counter variable which will count the occurrences of the numbers greater than 0.7
or less than -0.7and simultaneously check the condition whether r[i]*r[i] is greater than or equal to 0.5
if true then increase the counter variable.
Below is Java implementation of the same.Assume count has been initialized to 0.
for(int i=0;i<=r.length;i++)
{
if((r[i] >=0.7 || r[i]<=-0.7)&&(r[i]*r[i]>=0.5))
count++;
}
System.out.println(count);
For c implementation you would have to know the length of array to use a loop whereas in java length is an attribute of array type.
Please give it a thumbs up
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.