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 / kapil hansrajani
include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,n;
clrscr();
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element to search : ");
scanf("%d",&j);
for(i=0;i<n;i++)
{
if(a[i]==j)
{
printf("The position of the element %d is %d ",j,i);
break;
}
}
getch();
}
Is This Answer Correct ? | 48 Yes | 26 No |
Post New Answer View All Answers
Why double pointer is used in c?
Explain the difference between getch() and getche() in c?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
In C programming, how do you insert quote characters (‘ and “) into the output screen?
What is static memory allocation? Explain
What are the disadvantages of a shell structure?
Can we access array using pointer in c language?
What is a double c?
Differentiate between static and dynamic modeling.
what do you mean by inline function in C?
Explain how are portions of a program disabled in demo versions?
What does %2f mean in c?
Write the control statements in C language
Can we change the value of static variable in c?
differentiate built-in functions and user – defined functions.