using C programming You are given an array of integers arra


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 their square equals to x^2. In other words, you have to find out if there is any pan of i. j such that array [i]^2 + array [j]^2 = x^2. If there are such pairs, you should print all such (1 j). Otherwise print \"There are no such pairs\'\". Example: array[]: 2S -4r 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) The array size is 10 and you have to get the elements of the array from the user. You also need to take the value of \"x from the user.

Solution

the following is the program to do the required

#include <stdio.h>
int main(void)
{
   //variables to be used
int i, n,j,xsquare,square1,square2;
   int array [10];
  

//input the value of x
printf(\"Enter the value of x: \");
scanf(\"%d\", &n);
   // x sqaure value is calculated here
   xsquare = n*n;
  
   printf(\"Enter the numbers for array (max 10 allowed): \");
   for (i=0;i<10;i++) {
       scanf(\"%d\",&array[i]);
   }
  
  
   //for loop for matching pairs
for (i = 0; i <= 9; i++){
for (j = 0; j <= 9; j++){
square1 = i*i;
square2 = j*j;

//compare the array square plus the input one
if(xsquare == square1 + square2)
printf(\"The pair are %d and %d\",j,i,xsquare);
}
}
return 0;
}

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site