SearchArrayUse the following starter program:#include #include #define NUMNUMS 9int mainint datal 14, 5, 8,9, 13, 22,44, 55, 65 )return O;Write code that does the following:1. Ask the user for a number to search for2. Search the data array to see if the number is there.3. If the number is there, say number found, otherwise say number not found.Please enter a number for which you would like to search:22number foundprocess returned θ (0x8) execution time : 2.467 sPress any key to continue.

Question
Asked Mar 14, 2019
17 views

Programming in C 

SearchArray
Use the following starter program:
#include <stdio.h>
#include <stdlib.h>
#define NUMNUMS 9
int main
int datal 14, 5, 8,9, 13, 22,44, 55, 65 )
return O;
Write code that does the following:
1. Ask the user for a number to search for
2. Search the data array to see if the number is there.
3. If the number is there, say number found, otherwise say number not found.
Please enter a number for which you would like to search:22
number found
process returned θ (0x8) execution time : 2.467 s
Press any key to continue.
help_outline

Image Transcriptionclose

SearchArray Use the following starter program: #include <stdio.h> #include <stdlib.h> #define NUMNUMS 9 int main int datal 14, 5, 8,9, 13, 22,44, 55, 65 ) return O; Write code that does the following: 1. Ask the user for a number to search for 2. Search the data array to see if the number is there. 3. If the number is there, say number found, otherwise say number not found. Please enter a number for which you would like to search:22 number found process returned θ (0x8) execution time : 2.467 s Press any key to continue.

fullscreen
check_circle

Expert Answer

Step 1

We use the bsearch function from the stdlib.h and define a compare function to return the result of comparison of two integers. We prompt the user for input and then call the bsearch function which uses the compare function defined by us.

Step 2

The C program is shown below:

#include <stdio.h>

#include <stdlib.h>

 

//function to compare two integers

int compareInt(const int *a, const int *b) {

   return (int) (*a - *b);

}

 

int values[] = { 4,5,8,9,13,22,44,55,65 };

 

int main () {

   int *item;

   int key;

   //prompt user and accept input

   printf("Enter a number to search:");

   scanf("%d",&key);

   //call bsearch function from stdlib and use ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Construct a dfa that accepts the language generated by the grammar S → abA, A → baB, B → aA|bb.

A: Deterministic finite automata (DFA):

question_answer

Q: Use Eclipse for do this program. Show the output of the following statements.a) System.out.printf("a...

A: The program has the following algorithm:a) The statement print the amount in floating point and expo...

question_answer

Q: 12 4x)x,is an another form of representation of fuzzy set. A, (x) /x, is an another form of represen...

A: A fuzzy set is a pair X, m(A)) where X is a Universal set and mA) is a membership function or degree...

question_answer

Q: Create a new file in c++.  In this lab, you will add some functionality to the table ofmenu. Your bo...

A: Program Instructions:Declare variables and write a welcome message.Always convert the user's choice ...

question_answer

Q: how to write a function in python 3 that reads a txt file which includes three number (each line has...

A: AlgorithimStartOpen a file in read modeRead a line from file and store the number in variable aRead ...

question_answer

Q: Draw a full-adder using only NAND gates.

A: The full adder circuit with NAND gates is shown below.  It is a simple 1 bit adder.

question_answer

Q: SQL(Oracle): How do I create an index for the number of days it takes to ship an order? i.e. shipdat...

A: Since we need to create an index based on a calculated field we need to create a calculated index. T...

question_answer

Q: Function Name: leapYear Parameters: year – an nonnegative integer representing the year Test Cases: ...

A: Click to see the answer

question_answer

Q: Construct an npda corresponding to the grammar S→aABB|aAA,A→aBB|b,B→bBB|A.

A: Firstly, we will convert the given grammar into GNFS → aABB|aAAA → aBB|bB → bBB|aBB|a