Question

In: Computer Science

Write a program that allows the user to search the array to find the number entered

Write a program that allows the user to search the array to find the number entered

Solutions

Expert Solution

main.cpp

/* program that allows the user to search the array to find the number entered */

#include <iostream>
using namespace std;

int main()
{
   int array[100], search, c, n;

   cout<<"Enter the number of elements in array"<<endl;
   cin>>n;

   cout<<"Enter "<<n<<" integer(s) "<<endl;

   for (c = 0; c < n; c++)
      cin>>array[c];

   cout<<"Enter the number to search"<<endl;
   cin>>search;

   for (c = 0; c < n; c++)
   {
      if (array[c] == search)     /* if required element found */
      {
        cout<<search<<" is present at location "<< c+1<<endl;
         break;
      }
   }
   if (c == n)
      cout<<search<<" is not present in array"<<endl;

   return 0;
}

Output:-

Enter the number of elements in array
5
Enter 5 integer(s) 
10
20
30
40
50
Enter the number to search
40
40 is present at location 4

Related Solutions

Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
Add a function to Programming Challenge 7 that allows the user to search the structure array...
Add a function to Programming Challenge 7 that allows the user to search the structure array for a particular customer's account. It should accept part of the customer's name as an argument and then search for an account with a name that matches it. All accounts that match should be displayed. If no account matches, a message saying so should be displayed. Currently I have #include <iostream> #include <string> using namespace std; void displayAccount(struct customerAccount Arr[], int index); void changeAccount(struct...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number of data set. 2- Allows the user to exit the program at any time by entering zero. 3- Calculates and displays the following statistics for the entered data set: a- Count of positive, negative, and total numbers. b- Maximum and Minimum numbers. c- Sum and Average of positive numbers. d- Sum and Average of negative numbers. e- Overall Sum and overall average of all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT