WAP to count the repeated location
#include<conio.h>
#include<iostream.h>
void main()
{
int item,a[20],n,i,count=0,loc=0;
cout<<"\n enter size of array :";
cin>>n;
cout<<"\n enter element of array :";
for(i=1;i<=n;i++)
cin>>a[i];
cout<<"\n enter element which is to be search :";
cin>>item;
cout<<"\n The no of location is :";
i=1;
while(i<=n)
{
if(a[i]==item)
{
count=count+1;
cout<<i<<",\t";
i++;
}
else
{
i++;
}
}
if(a[i]==item)
cout<<"\n Total no. of repeated given element :"<<count;
else
cout<<"\n element is found";
getch();
clrscr();
}
No comments:
Post a Comment