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
What is the role of this pointer?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
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
What is the purpose of type declarations?
simple program of graphics and their output display
Difference between pass by reference and pass by value?
What are the 4 data types?
What is extern variable in c with example?
Why can arithmetic operations not be performed on void pointers?
what is the function of pragma directive in c?
What is extern c used for?
The __________ attribute is used to announce variables based on definitions of columns in a table?
Why #include is used in c language?
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.
What is difference between Structure and Unions?