c programming.
Given a sorted array of 20 integers and a target integer value,
your program needs to print out all pairs of
integers which have sum equal to the target value. If there is no
pair of integers to return, print out “No
pair of integers in the given array can be summed to the target
value”. The array of integers and the target
value should be given from the keyboard (taken as user
input).
Inputs and Outputs should be taken from main.c and passed to this
function, the final output should be printed in main.c
ex) int[][]array(int nums[])
{
return {{}}
}
must return 2d array please help!
Answer: here is the answer for your question :
--------------------------------------------------------------------------------------------------------------------------------------------------------
CODE IN C++:
#include <stdio.h>
void array(int arr[],int n)
{
printf("Printing the array:\n");
for(int i=0;i<20;i++)
{
printf("%d",arr[i]);
printf("\t");
}
int flag=0;
printf("Printing all pairs that sum to given value:\n");
for (int i=0;i<20;i++)
{
for(int j=i+1;j<20;j++)
{
if(arr[i]+arr[j]==n)
{ flag=1;
printf( "{ %d , %d }",arr[i],arr[j]);
printf("\n");
}
}
}
if(flag==0)
printf("No pair of integers in the given array can be summed to the
target value\n");
}
int main()
{
int arr[20],n;
printf("Welcome to the program !!!!\n");
printf("Enter the value of item to be searched\n");
scanf("%d",&n);
printf("Enter the values in array:\n");
for(int i=0;i<20;i++)
{
printf("Enter value:\n");
scanf("%d",&arr[i]);
}
array(arr,n);
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
CODE SNIPPET:

--------------------------------------------------------------------------------------------------------------------------------------------------------
CODE OUTPUT:


please note that here i am printing the numbers that sum to given value . i am not able to understand what you mean by return a 2-d matrix. what 2-d matrix would contain ??
so ,if you need any more help, please provide comments below the answer . i will help you out
thanks
c programming. Given a sorted array of 20 integers and a target integer value, your program...
Given a sorted (in ascending order) integer array nums of n elements and a target value, write a method to perform a binary search for a target value in nums. If target exists, then return its index, otherwise return -1. Analyze the running time, T(n). public int search(int[] nums, int target) { // YOUR CODE GOES HERE } // end search
IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...
Write a C++ function binsearch that carries out the binary search algorithm on a sorted array of integers. Your function takes as parameters an array of integers (sorted in increasing order), the size of the array, and a target integer to search for. The function returns the index of the target in the array, and returns -1 if the target is not in the array. The file main1.txt on the webpage contains code that generates a specific array of integers...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...
****Coral Please**** Given a sorted list of integers, output the middle integer. Assume the number of integers is always odd. Ex: If the input is 2 3 4 8 11 -1 (a negative indicates end), the output is: 4 The maximum number of inputs for any test case should not exceed 9. If exceeded, output "Too many inputs". Hint: Use an array of size 9. First read the data into an array. Then, based on the number of items, find...
USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b, where a – b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a – b = 3 A = [10, 4, 6, 16, 1, 6, 12, 13] Then your method should return the following pairs: 4, 1 15, 12 13, 10 A poor solution: There are...
You are given an array A of integers in sorted order. However, you do not know the length n of the array. Assume that in our programming language arrays are implemented in such a way that you receive an out-of-bounds error message whenever you wish to access an element A[i] with i>n. For simplicity we assume that the error message simply returns the value INT_MAX and that every value in the array is smaller than INT_MAX. (a) Design an algorithm...
the
programming language is in java
Problem 2 You are given an array A with n distinct elements. Implement an (n log n)-time algorithm that creates an array B where all elements are in range from 0 to n - 1 and where the order of elements is the same as in A. That is, 0 has the same index in B as the smallest element in A, 1 has the same index in B as the second smallest element...
Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...