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 the output. Name program part1.c
int search(int a[], int n, int value);
Example 1:
Enter length of array: 4
Enter elements of array: 8 2 3 9
Enter the value for searching: 2
Output: 1
Example 2:
Enter the length of the array: 6
Enter the elements of the array: 4 6 1 0 2 9
Enter the value for searching: 5
Output: -1
2. Modify the part 1 program so that it deletes all instances of the value from the array. As part of the solution, write and call the function delete() with the following prototype. n is the size of the array. The function returns the new size of the array after deletion (The array after deletion will be the same size as before but the actual elements are the elements from index 0 to new_size-1). In writing function delete(), you may include calls to function search(). The main function takes input, calls the delete()function, and displays the output. Name your program part2.c.
int delete(int a[], int n, int value);
Example 1:
Enter the length of the array: 6
Enter the elements of the array: 4 3 1 0 3 9
Enter the value for deleting: 3
Output array:
4 1 0 9
ANSWER:-
QUESTION (1):-
#include <stdio.h>
int search(int arr[],int n,int value)
{
for(int i=0;i<n;i++)
{
int index=-1;
if(arr[i]==value)
{
index=i;
return
index;
}
}
return -1;
}
int main(void) {
int n,num;
printf("Enter length of array : ");
scanf("%d",&n);
int arr[n];
printf("Enter elements of array : ");
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("Enter the value for searching : ");
scanf("%d",&num);
int index=search(arr,n,num);
if(index>=0)
printf("index value is %d",index);
else
printf("invalid searching value ");
return 0;
}
// OUTPUT:

QUESTION (2):-
#include <stdio.h>
int search(int arr,int value)
{
if(arr==value)
return 1;
else
return 0;
}
int delete(int arr[],int n,int value)
{
for(int i=0;i<n;i++)
{
int k=search(arr[i],value);
if(k==1)
{
for(int j=i;j<n;j++)
arr[j]=arr[j+1];
n--;
}
}
printf("Modified array : ");
for(int i=0;i<n;i++)
printf("%d ",arr[i]);
}
int main(void) {
int n,num;
printf("Enter length of array : ");
scanf("%d",&n);
int arr[n];
printf("Enter elements of array : ");
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("Enter the value for searching : ");
scanf("%d",&num);
delete(arr,n,num);
return 0;
}
OUTPUT:-

// If any doubt please comment
Success #stdin #stdout Os 4496KB Enter length of array 4 Enter elements of array 8 2 3 9 Enter the value for searching 2 index value is 1
Success #stdin #stdout Os 4564KB Enter length of array 6 Enter elements of array 4 3 1 0 3 9 Enter the value for searching : 3 Modified array : 4 0 3 9
In C language Write a program that includes a function search() that finds the index of...
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...
Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...
Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...
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...
The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an array in ascending order. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that...
Write a program in C++ language that finds the largest number in an array of positive numbers using recursion. Your program should have a function called array_max that should pass in an int array, and an int for the size of the array, respectively, and should return an int value. As an example, given an array of size 10 with contents: {10, 9, 6, 1, 2, 4, 16, 8, 7, 5} The output should be: The largest number in 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...
follow the instructions inside. You are to implement the sequential search of array elements. User will enter a value (size) which represents the number of values to process The values entered will be stored in an array of type short that has 1000 elements User will enter size numbers The user will enter a search value The program will search the data for a specific value program will display a message in which element the value was found or display...
Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...
Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...