#include<stdio.h>
void main()
{
int a[10],i,e,n;
printf("Enter the size of array");
scanf("%d",&n);
printf("enter elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the elements to be search ");
scanf("%d",&e);
for(i=0;i<n;i++)
{
if(a[i]==e)
printf("The element is found");
break;
if(i==n)
printf(" The element not found");
}
}
OUTPUT:
1. Enter the size of array 7
enter elements 11
21
31
41
51
61
71
enter the elements to be search 51
The element is found
2. Enter the size of array 7
enter elements 11
21
31
41
51
61
71
enter the elements to be search 40
The element is not found
void main()
{
int a[10],i,e,n;
printf("Enter the size of array");
scanf("%d",&n);
printf("enter elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the elements to be search ");
scanf("%d",&e);
for(i=0;i<n;i++)
{
if(a[i]==e)
printf("The element is found");
break;
if(i==n)
printf(" The element not found");
}
}
OUTPUT:
1. Enter the size of array 7
enter elements 11
21
31
41
51
61
71
enter the elements to be search 51
The element is found
2. Enter the size of array 7
enter elements 11
21
31
41
51
61
71
enter the elements to be search 40
The element is not found
No comments:
Post a Comment