Computer Science, asked by Ldass21, 11 hours ago

Draw a flow chart and write down C program to take an array of 10 elements and print all
combinations of two elements whose sum is equal to 50.

Answers

Answered by aartitomarji
1

Answer:

what is the correct answer

Answered by shilpa85475
0

#include <stdio.h>    

     

int main()    

{    

     

   int arr[] = {1, 2, 3, 4, 5,6,7,8,9,10};      

   

   int length = sizeof(arr)/sizeof(arr[0]);    

       

   printf("Elements of given array: \n");    

   for (int i = 0; i < length; i++) {      

       printf("%d ", arr[i]);      

   }      

     

   return 0;    

}      

Explanation:

public class abc

{

   static void findThePairs(int inputArray[], int inputNumber)

   {

       System.out.println("Pairs of elements whose sum is "+inputNumber+" are : ");

 

       for (int i = 0; i < inputArray.length; i++)

       {

           for (int j = i+1; j < inputArray.length; j++)

           {

               if(inputArray[i]+inputArray[j] == inputNumber)

               {

                   System.out.println(inputArray[i]+" + "+inputArray[j]+" = "+inputNumber);

               }

           }

       }

   }

 

   public static void main(String[] args)

   {

       findThePairs(new int[] {4, 6, 5, -10, 8, 5, 20}, 10);

 

       findThePairs(new int[] {4, -5, 9, 11, 25, 13, 12, 8}, 20);

 

       findThePairs(new int[] {12, 13, 40, 15, 8, 10, -15}, 25);

 

       findThePairs(new int[] {12, 23, 125, 41, -75, 38, 27, 11}, 50);

   }

}

Similar questions