WAP to search an element in
array list.
include <stdio.h>
void main() {
int
LA[] = {1,3,5,7,8};
int
item = 5, n = 5;
int
i = 0, j = 0;
printf("The original array elements are :\n");
for(i = 0; i<n; i++) {
printf("LA[%d] = %d \n", i,
LA[i]);
}
while( j < n){
if( LA[j] ==
item ) {
break;
}
j = j + 1;
}
printf("Found element %d at position %d\n", item, j+1);
}
Output
The original
array elements are :
LA[0]
= 1
LA[1]
= 3
LA[2]
= 5
LA[3]
= 7
LA[4]
= 8
Found element
5 at position 3
WAP to search biggest and smallest element in array
lit.
#include<stdio.h>
void main()
{
int a[100],i,n,large,small;
printf("How many
elements:");
scanf("%d",&n);
printf("Enter the
Array:");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
large=small=a[0];
for(i=1;i<n;++i)
{
if(a[i]>large) large=a[i];
if(a[i]<small) small=a[i];
}
printf("The largest
element is %d",large);
printf("\nThe smallest element is %d",small);
}
Output
How many elements:5
Enter the Array:10
20
15
5
17
The largest element is 20
The smallest element is 5