Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using C programming You are given an array of integers \"array[]\" and an input

ID: 3794895 • Letter: U

Question


using C programming

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 then square equals to x^2. In other words, you have to find out if there is any pair of ij 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[]: 2, -4, 6, 3, 9, 0, -1, -9 x: 5 You have 1 pair: (-4)^2 + (3)^2 = 5^2, so your output would be corresponding array indices: (1, 3)

Explanation / Answer

#include <stdio.h>

int main(void) {
   // your code goes here
   int a[10],i,j,x;
   for(i = 0; i < 10; i++)
   {
       scanf("%d",&a[i]);
   }
   scanf("%d",&x);
   for(i = 0; i < 10; i++)
   {
       for(j = i+1; j < 10; j++)
       {
           if ((x*x) == (a[i]*a[i] + a[j]*a[j]))
           {
               printf("%d %d ", i,j);
           }
       }
   }
   return 0;
}