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
Explain what is a pragma?
how to make a scientific calculater ?
Explain what is the best way to comment out a section of code that contains comments?
What are the types of functions in c?
What is a null string in c?
Can we declare variable anywhere in c?
What are the types of pointers in c?
In a switch statement, explain what will happen if a break statement is omitted?
How do I determine whether a character is numeric, alphabetic, and so on?
Write a program to reverse a string.
Why is c faster?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Explain the term printf() and scanf() used in c language?
What will be your course of action for a push operation?
please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com