Write a function to search an item named searchKey in an array of 20 elements. Assumed the array has all integer value and also the search item is an integer.

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 19VE
icon
Related questions
Question

Write a function to search an item named searchKey in an array of 20 elements. Assumed the array has all integer value and also the search item is an integer.        

Expert Solution
Step 1

Step 1:-

 

Program Approach:-

 

  1. Use one header file
  2. Declare user-defined function search(int *Ar, int searchkey) that takes the address of the array as a first parameter and element in the second parameter.
  3. Declare 3 variable in the main() function
  4. Declare one variable in the search() function
  5. Declare one Array of type integer

 

Step 2

Step 2:-

 

Explanation:-

 

1.The User-defined function is defined as a function that is designed by the user based on his requirement.

2.Pointer variable is a special variable that takes the address of another variable for example int *Ar

3.Array is defined as a similar type of data for example int A[2] array name is A and its data type is an integer. It takes two-element inside the array. The first element is store at location A[0]

4.== is used to compare the two values

 

Program:-

 

#include <stdio.h>

void search(int *Ar,int searchkey); //function declaration

 

int main()

{   

    int Arr[20];

    int i,term;

    printf("Enter the array element");

    for(i=0;i<20;i++)

    {

        scanf("%d",&Arr[i]);

    }

    printf("Enter the element that you want to search");

    scanf("%d",&term);

    search(&Arr,term);   //call the function

   

 

    return 0;

}

void search(int *Ar,int searchkey)  //function definition

{

    int c;

   for(c = 0; c <20; c++)

    {

        if(Ar[c] == searchkey)

        {

            printf("Element found in the array");

            break;  // terminate the loop

        }

    }

}

 

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning