Write a Program to Search a Element in Array and Show its Address index.
#include<iostream.h> #include<conio.h> #define MAXARRAY 10 void main(){ //Clean Screen or Clear Old Content clrscr(); //Variables int len=0,i=0,Array[MAXARRAY],search,addr,found=0; //Length of Array cout<<"Enter the Length of An Array : "; cin>>len; //Condition to Match MAXARRAY SIZE if(len>MAXARRAY) cout<<"---SOORY Max Length of An Array is 10 ---"; else{ // Enter Data in Arry for(i=0;i<len;i++){ cout<<"Enter Element for Array["<<i<<"] : "; cin>>Array[i]; } //Search cout<<"Enter the Element to Search in ARRAY : "; cin>>search; for(i=0;i<len;i++){ if(Array[i]==search){ addr=i; found=1; break; } } if(found) cout<<" Element Found at Array["<<addr<<"] = "<<search; else cout<<"---SOORY Element NOT Found in ARRAY---"; } getch(); }
Program Output :
(Visited 99 times, 1 visits today)
Written by: