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.
Answer:
(B)
Step-by-step explanation:
Since the base of the cone and one circular face of the cylinder is not visible,
The surface area of the rocket=Base Area of the Cylinder+Lateral area of the Cylinder+Lateral Area of the Cone+
Lateral Area of a Cone
- Base radius, r= 8/2 =4 Inches
- Perpendicular Height of the Cone = 3 Inches
Using Pythagoras theorem:
- Slant Height of the Cone, l (Hypotenuse) = 5 Inches
Therefore: Lateral Area of a Cone
Therefore, Surface area of the rocket
The triangle look late but you can bring it around