Write a C program that is uses a function to search for a specific value in a two dimensional array using quick search
The answer to the question is given
below.
For the fast search, the 2-D array has to be sorted over rows and
columns wise.
The C code for the problem is given below.
#include<stdio.h>
int search(int row, int column,int arr[][column],int key)
{
int min=arr[0][0]; /* taking starting element as minimum */
int max=arr[row-1][column-1]; /* bottom right element is maximum
*/
if(key<min || key>max) /* if key is not between min and max
then it is not available in array */
{
return -1;
}
int i=0;
int j=column-1;
while(i<row && column>=0) /* traversing the matrix
*/
{
if(arr[i][j]==key)
{
printf("Key is found at index %d %d",i,j); /*
when found the key, displaying its index */
return 1;
}
if(arr[i][j]>key) /* if key is larger than any
element than we will back to previous column, because matrix is
sorted column wise and row wise*/
{
j--;
}
else /* if key is smaller than any element than we
will back to previous row */
i++;
}
printf("\n Element is not in the array"); /* after traversing the
complete matrix if we get nothing, then element is not in the array
*/
return 0;
}
int main()
{
int row,column;
printf("Please Enter The Rows and Columns: ");
scanf("%d%d",&row,&column);
int i,j;
int arr[row][column];
printf("Please Enter The Elements of 2D
array:\n");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("Enter the Element You want to Search:
");
int key;
scanf("%d",&key);
int result=search(row,column,arr,key); /* calling the
search function */
if(result==1)
{
printf("\nThank You for using the
program");
}
else
{
printf("\nSearching Element should
be in the list");
}
return 0;
}
The screenshot of the running code is given below.
![1 #include<stdio.h> 2 int search(int row, int column, int arr[][column], int key) 30{ 4 int min=arr[0][0]; int max=arr[row-1]](http://img.homeworklib.com/questions/32df4750-95cc-11ea-8b3d-03fce78c94cc.png?x-oss-process=image/resize,w_560)

The screenshot of the sample input-output is given below.

If the answer helped please upvote it means a lot. For any query
please comment.
Write a C program that is uses a function to search for a specific value in...
In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...
In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional array. Within C program (the MAIN function); Declare a two- dimensional 3X2 integer array A and initialise with the values (1,2), (3,4), (5,6), declare also a two-dimensional 2X3 integer array B and initialise it with zero. Call the FUNCTION and pass arrays A and B to the FUNCTION as arguments. Print the array A and its transpose....
in C++ write a FUNCTION not the entire program to search an array for a given number and return its index (position)
In C++ for 2D Array:
Write a program that uses a function that manipulates a 2D array of integers as follows: 1. Fill the first row and column in the array with random bits 2. Every subsequent cell should be filled as follows: 1. If the cells that are to the left and top of it are equal, then you should store their sum in it b. Otherwise, your program should store the highest among them. Test your function using...
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...
In C++: 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. Using the code below, add your binsearch function to this C++ program. (Do...
Write and test a function in C++ that uses the binary search algorithm to search an array of sorted strings – use a do..while loop to allow user to perform multiple searches w/o terminating the program – see sample output below. Use this name array: string names[SIZE] = { "Collins, Bill", "Smith, Bart", "Allen, Jim", "Griffin, Jim", "Stamey, Marty", "Rose, Geri", "Taylor, Terri", "Johnson, Jill", "Allison, Jeff", "Looney, Joe", "Wolfe, Bill", "James, Jean", "Weaver, Jim", "Pore, Bob",...
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...