GoogelAddUnit1

Monday 16 April 2012

WRITE A C-PROGRAM TO FIND THE LOCATION OF THE REQUIRED ELEMENT.

 AIM:A program to find the location of the required element


PROGRAM:
#include<stdio.h>
main()
{
int i,n,a[100],m,x,f=0;
printf("enter the value of n");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the required element");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(a[i]==x)
{
m=i;
f++;
}
}
if(f==0)
printf("the required element is not found");
else
printf("the required element is found in the list and the position is%d",m);
}

OUTPUT:
enter the value of n
5
the required element is found in the list

No comments:

Post a Comment