Breaking News
recent

WAP to find the location of an element of an array

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i,n,x;
cout<<"enter the no. of element :";
cin>>n;
cout<<"Enter the elements :"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Elements of array are :"<<endl;
for(i=0;i<n;i++)

cout<<"a["<<i<<"]"<<"="<<a[i]<<endl;

cout<<"Enter the element whose location is to be found: ";
cin>>x;
for(i=0;i<n;i++)
{
  if(a[i]==x)
cout<<"a["<<i<<"]"<<endl;
}
getch();

}

Output:


Unknown

Unknown

No comments:

Post a Comment

Powered by Blogger.