1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Maksim231197 [3]
3 years ago
6

You are given an array of integers "array []" and an input "x". you have to find if there are any two numbers in your array such

that the sum of their square equals to x2 . in other words, you have to find out if there is any pair of i,j such that array[i]2 + array[j]2 = x 2 . if there are such pairs, you should print all such (i,j). otherwise print "there are no such pairs". example: array []: 6, -4, 6, 3, 9, 0, -1, -9, 2, 6 x: 5 you have 1 pair: (-4) 2 + (3) 2 = 5 2 so, your output would be corresponding array indices: (1, 3) note: the array size is 10 and you have to get the elements of the array from
Mathematics
1 answer:
Vesnalui [34]3 years ago
3 0
Given an integer array a, size n, and an input integer value x..  Need to find all pairs of members a[i], a[j] such that (a[i],a[j],x) form a Pythagoras triplet, with x>a[i], a[j].

We need a double loop, the outer loop for a[i], and the inner loop finds a[j].
Here's a pseudocode.

int i, j, x, i2, x2, count=0; 
input x;
x2=x*x;   // economizing on cycles
if x<0 {x=-x};
for i=1 to n-1 {
  if x>=i {      // skip processing the impossible
    i2=i*i;      // economizing on cycles     
    for j=2 to n {
      if x>=j {     // skip processing the impossible
         if i2+j*j==x2 {
            count++;
            print(i,j);
         }
      }
    }
  }
}
if count==0 { print("there are no matched pairs");

It will have a similar complexity as a bubble sort, n^2/2.


You might be interested in
A scuba diver is swimming 28 feet below the water’s surface. The diver swims up slowly at a rate of 0.3 feet per second for 6 se
NISA [10]

Answer:

27.4 feet down deep

Step-by-step explanation:

28 feet down, swins up for 0.3 feet times 6 or 1.8 feet up

leaving a total of 26.2 under the sea and he swims back down at 0.3 feet times 4 or 1.2 feet down. and the new total is 26.2 + 1.2 which equals 27.4 feet down in the deep sea

8 0
3 years ago
Read 2 more answers
Jeff worked 4 and 2/3 hours in the morning and 3 and 3/4 hours in the afternoon. How many total hours did he work
Aleksandr-060686 [28]

Answer:

4. 8 5/12

Step-by-step explanation:

4 2/3 + 3 3/4 =

= 4 + 2/3 + 3 + 3/4

= 4 + 3 + 8/12 + 9/12

= 7 + 17/12

= 7 + 12/12 + 5/12

= 7 + 1 + 5/12

= 8 5/12

4 0
3 years ago
Which graph represents a quadratic function with a vertex at (0, 0)? On a coordinate plane, a parabola opens up. It goes through
olchik [2.2K]

Answer:

  On a coordinate plane, a parabola opens up. It goes through (negative 5, 6), has a vertex of (0, 0), and goes through (5, 6).

Step-by-step explanation:

Since you want a graph with a vertex of (0, 0), choose the one that is described as having a vertex of (0, 0).

5 0
3 years ago
Read 2 more answers
Check my answer ASAP
babymother [125]

Answer:

first- B

second- correct

third- correct

8 0
4 years ago
Please HELP me with these and explain. i did these but i wanna make sure they are right.
neonofarm [45]
6.739 = 6.7 to the tenth place
52.192 = 52.2 to the tenth place
0.61 = 1 to the unit(ones) place
348.508 = 348.51 to the hundredth place
3 0
3 years ago
Read 2 more answers
Other questions:
  • Dee's credit card has an APR of 17% calculated on the previous monthly balance, and Dee makes a payment of $50 every month. Her
    5·2 answers
  • A race was 11/12 mile long.Hamish ran 4/5 of the distance. Without multiplying explain how you know that the answer must be less
    12·1 answer
  • The beginning balance on the monthly bank statement for ians checking account was $289.37 and the ending balance was $409.28, wh
    10·2 answers
  • If f(x) = 1-x2 and g(x) = 1 - x which is the rule of function (f – g)(x)?
    6·1 answer
  • Which one is the right answer
    10·1 answer
  • A bag contains 1 red, 1yellow, 1 blue, and 1 green marble. What is the probability of choosing a green marble not relplacing it,
    8·1 answer
  • X+y=1 If x=0, then y=
    14·1 answer
  • The table below shows how the mass of household waste in the UK has changed from 2004 to 2012. Calculate the percentage of house
    9·1 answer
  • Which ordered pair is a solution to the system of equalities y&lt;3x y&lt;5
    13·1 answer
  • What is 14/35 as a percent?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!