write a program to search for an element in a given array.
If the array was found then display its position otherwise
display appropriate message in c language

Answer Posted / poorni

#include<stdio.h>
#include<conio.h>

int main()
{
int a[20],i,temp=0,n,pos=0,element;
//clrscr();
printf("Search an Element in Array\n");
printf("Enter the number of elements: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the value for elements: ");
scanf("%d",&a[i]);
}
printf("Enter the searching element: ");
scanf("%d",&element);
for(i=0;i<n;i++)
{
if(a[i]==element)
{
temp=1;
pos=i;
}
}
if (temp==1)
printf("Element found %d , position=%
d",element,pos);
else
printf("Element not found\n");
getch();
}

Is This Answer Correct ?    56 Yes 31 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define macros.

778


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

1366


Explain what are its uses in c programming?

590


Explain goto?

709


cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

630






write an algorithm to display a square matrix.

2218


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

721


What is main () in c?

584


What is the right type to use for boolean values in c? Is there a standard type?

557


In c programming language, how many parameters can be passed to a function ?

626


Where register variables are stored in c?

541


Is register a keyword in c?

629


Write a program to find the biggest number of three numbers in c?

586


What is the difference between typedef struct and struct?

592


Which is more efficient, a switch statement or an if else chain?

572