Blogger templates

Pages

Saturday 30 June 2012

WAP of C Language that Search For a Desired Element in an Array of N Natural Numbers

 Search Array Element
Statement of C Program: This Program Searches for a desired element in a set of n Numbers:

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i , found , key_element ;
int listn[20];
clrscr();
printf(" Enter the Number of elements in the Array\n");
scanf("%d" , &n);
printf(" Enter %d Numbers\n" , n);
for(i=0 ; i<n ; i++)
{
scanf("%d" , &listn[i]);
}

printf("Enter the Key element\n");
for(i=0 ; i<n ; i++)
{
if(listn[i] == key_element)
{
found = 1;
}
}
                                                      /* End of for */
if(found)
{
printf(" Key element is found")
}
else
{
printf(" Key element is not found in the list\n");
}
getch();
}

Output:
Enter the number of elements in the Array
4
Enter 4 elements
16
25
37
49
Enter the key elements
37
Key element is found

                                                            That's All

0 comments:

Post a Comment