Wednesday, November 11, 2009

29.WAP TO SEARCH AN ELEMENT IN A ARRAY

//WAP TO SEARCH AN ELEMENT IN A ARRAY
#include
#include
void main()
{
int a[30],n,i,item,loc,count=0;
clrscr();
printf("\nENTER THE NO OF ELEMENTS=");
scanf("%d",&n);
printf("ENTER NO'S=");
for(i=0;iscanf("%d",&a[i]);
printf("\n\nENTER ITEM TO BE SEARCHED=");
scanf("%d",&item);
for(i=0;i{
if(a[i]==item)
{
loc=i;
printf("\n\n%d IS PRESENT AT LOC %d",item,loc);
count++;
}}
if(count!=0)

printf("\n\nTHE NO IS PRESENT %d TIMES",count);
else

printf("\nTHE NO IS NOT PRESENT");


getch();
}
/*-------------------------------------------------------------------
OUTPUT
----------------------------------------------------------------------

ENTER THE NO OF ELEMENTS=5
ENTER NO'S=1
2
3
1
5


ENTER ITEM TO BE SEARCHED=1


1 IS PRESENT AT LOC 0

1 IS PRESENT AT LOC 3

THE NO IS PRESENT 2 TIMES
*/



3 comments:

  1. u hav take some mistakes in "for" Loop....correct that mistakes.....

    ReplyDelete
  2. my dear frnd its nt a mistke....the syntax of for loop is matching wid dat of HTML code...wch is creatng prblm...dnt worry i'll rectify it...

    ReplyDelete
  3. in dis prgrm ...the for loop is strtng frm i=0 to i is less than "n" then i++...

    ReplyDelete

Programming the Whole World!