My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to search a number present in number of times in the array and also find its location

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int x[50],n,m;
 cout<<"enter number of elements in the array: ";
 cin>>n;
 cout<<"enter the elements"<<endl;
 for(int i=0;i<n;i++)
 cin>>x[i];
 cout<<"enter the element to be searched: ";
 cin>>m;
 int count=0;
 for(int j=0;j<n;j++)
 {
   if(x[j]==m)
   {cout<<m<<" is present at location "<<"x["<<j<<"]"<<endl;
   count+=1;}
   }
   cout<<m<<" present the number of times= "<<count;
   getch();
   }

0 comments: