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
Define macros.
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.....
Explain what are its uses in c programming?
Explain goto?
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
write an algorithm to display a square matrix.
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
What is main () in c?
What is the right type to use for boolean values in c? Is there a standard type?
In c programming language, how many parameters can be passed to a function ?
Where register variables are stored in c?
Is register a keyword in c?
Write a program to find the biggest number of three numbers in c?
What is the difference between typedef struct and struct?
Which is more efficient, a switch statement or an if else chain?