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


Please Help Members By Posting Answers For Below Questions

Why double pointer is used in c?

783


Explain the difference between getch() and getche() in c?

742


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

879


In C programming, how do you insert quote characters (‘ and “) into the output screen?

1230


What is static memory allocation? Explain

823


What are the disadvantages of a shell structure?

950


Can we access array using pointer in c language?

847


What is a double c?

773


Differentiate between static and dynamic modeling.

841


what do you mean by inline function in C?

830


Explain how are portions of a program disabled in demo versions?

872


What does %2f mean in c?

961


Write the control statements in C language

867


Can we change the value of static variable in c?

754


differentiate built-in functions and user – defined functions.

871