google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a C++ program to find position of an element in the array using linear search method - 2nd puc computer science

Write a C++ program to find position of an element in the array using linear search method

 /*Write a C++ program to find position of an element in the array using linear search method.*/

#include<iostream.h>

#include<conio.h>

void main( )

{

int a[50], i, pos, ele, n;

clrscr( );

cout<<"Enter the number of elements:"<<endl;

cin>>n;

cout<<"Enter the elements:"<<endl;

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

cin>>a[i];

cout<<"Enter the search element:"<<endl;

cin>>ele;

pos=-1;

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

if(ele == a[i])

{

pos = i;

break;

}

if(pos >= 0)

cout<<"The search element "<<ele<<" is present at position "<<pos<<endl;

else

cout<<"The search element "<<ele<<" is not present"<<endl;

getch( );

}

Write a C++ program to find position of an element in the array using linear search method Write a C++ program to find position of an element in the array using linear search method Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.