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 / anuja kulkarni

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

void main()
{
int a[5],i;
int ele,temp=0,pos=0;

clrscr();
printf("enter the array elements\n");
for (i=0; i<5; i++)
scanf("%d",&a[i]);
printf("Enter the element to be search\n");
scanf("%d",&ele);

// searching for the element

for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
pos=i;
}
}

if (temp==1)
printf("Element found %d , position==%d",ele,pos);
else
printf("Element not found\n");
} // end of main()

Is This Answer Correct ?    483 Yes 132 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the role of this pointer?

753


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2352


What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

872


What is the purpose of type declarations?

878


simple program of graphics and their output display

1703


Difference between pass by reference and pass by value?

863


What are the 4 data types?

765


What is extern variable in c with example?

758


Why can arithmetic operations not be performed on void pointers?

811


what is the function of pragma directive in c?

877


What is extern c used for?

763


The __________ attribute is used to announce variables based on definitions of columns in a table?

954


Why #include is used in c language?

789


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1696


What is difference between Structure and Unions?

872