To search an element from an array.
If this program give any error please let me know..
May this program helps you a lot!!
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int i,n,searchnumber,num[10];
cout<<"Enter the size of the array:";
cin>>n;
cout<<"***The entered numbers are***"<<endl;
for(i=0;i<n;i++)
{
cout<<"Enter numbers in an array"<<endl;
cin>>num[i];
}
cout<<"enter number to be searched:"<<endl;
cin>>searchnumber;
for(i=0;i<n;i++)
{
if (num[i]==searchnumber)
{
cout<<searchnumber<< "is found at location" <<i<<endl;
}
}
getch();
return 0;
}
If this program give any error please let me know..
May this program helps you a lot!!
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int i,n,searchnumber,num[10];
cout<<"Enter the size of the array:";
cin>>n;
cout<<"***The entered numbers are***"<<endl;
for(i=0;i<n;i++)
{
cout<<"Enter numbers in an array"<<endl;
cin>>num[i];
}
cout<<"enter number to be searched:"<<endl;
cin>>searchnumber;
for(i=0;i<n;i++)
{
if (num[i]==searchnumber)
{
cout<<searchnumber<< "is found at location" <<i<<endl;
}
}
getch();
return 0;
}
No comments:
Post a Comment