Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program in C++ that inputs data into an array. It inputs a value from the user and searches this value in the array using sequential search.

Posted on October 26, 2021 By myustaadg.com
Spread the love

Write a program in C++ that inputs data into an array. It inputs a value from the user and searches this value in the array using sequential search. If the entered value is found in the array, it displays the position of the value in the array; otherwise, it displays the message “Value not found”.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Code:

Write a program in C++ that inputs data into an array. It inputs a value from the user and searches this value in the array using sequential search.

#include"iostream" 
using namespace std;
main()
{
int arr[5], n, i, pos;
i = 0;
while(i<=4)
{
cout<<"Enter value in element "<<i<<"? "; 
cin>>arr[i];
i++;
}
pos = 0;
cout<<"Enter any value ? ";
cin>>n;
i = 0;
while(i<=4)
{
if(n == arr[i])
{
pos = i + 1;
break;
}
i++;
}
if(pos == 0)
cout<<"Value not found "<<endl;
else
cout<<"Value found at position = "<<pos<<endl;
}

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/

Arrays Exercises, Programming Exercises Tags:array declaration in c++, Array Exercises, Array exercises in C++, array in Object oriented programming, array in OOP, array programming, Arrays, arrays codes, Arrays exercises, Arrays in C++, Arrays in C++ Programming with examples, Arrays in Programming, Arrays with example, C++ array: declare, C++ Arrays (With Examples), c++ arrays declaration and initialization, C++ Arrays with examples, C++ Program Linear Search in Array, C++ Program to Implement Linear Search Algorithm, C++ Program to search an element in an array using the function, C++ Programming/Exercises, Creating and Using Arrays, finding elements in an array using a function c++, how do you initialize an array in c++, Linear search in C++ Program Example Code, Search an element in array, Searching Arrays – Programming Fundamentals, Sequential Search in C++ with examples, Simple arrays code, Simple Searching In Array C++ Example Program, Write a program in C++ that inputs data into an array. Is inputs a value from the user and searches this value in the array using sequential search., Write a program in C++ that inputs data into an array. It inputs a value from the user and searches this value in the array using sequential search.

Post navigation

Previous Post: Write a program that inputs temperatures for seven days of the week into a one-dimensional array “temp”.
Next Post: Write a program that sorts one-dimensional array of 5 elements in ascending order using insertion sort method.

More Related Articles

Write a program to initialize values in two tables A and B. Multiply matrix A and B and store results into table C | Multiplication of matrices. Arrays Exercises
Write a program that input user name and displays on the screen in python | Python Programming Programming Exercises
Write a program that sorts one-dimensional array’s values into descending order using the bubble sort method. Arrays Exercises
Write a program that initializes values in a table and searches for a value from it. If value is found, then it displays the value and its location. Arrays Exercises
Write a program that initializes data into a one-dimensional array. Search value using binary search. Arrays Exercises
Write a Program to Build a Simple Calculator in C# Write a Program to Make a Simple Calculator in C# Programming Language | Solved Programming Exercises Programming Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme