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 / sunil makwana
#include<stdio.h>
#include<conio.h>
void searchval(int a[5],int n)
{
int i,temp=0,pos=0;
for (i=0; i<5; i++)
{
// printf("value of array:: %d",i);
if (a[i]==n)
{
temp=1;
pos=i;
}
}
if (temp==1)
{
printf("Element found %d , position==%d",n,pos);
}
else
{
printf("Element not found\n");
}
}
void main()
{
int a[5],i,n;
int ele,pos,temp;
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);
searchval(a,ele);
getch();
}
| Is This Answer Correct ? | 29 Yes | 17 No |
Post New Answer View All Answers
Which is better oop or procedural?
How does selection sort work in c?
What does d mean?
What are external variables in c?
write a program to print data of 5 five students with structures?
Describe static function with its usage?
What is const and volatile in c?
What is the argument of a function in c?
What is bubble sort technique in c?
What does calloc stand for?
What is the difference between a string and an array?
what is the difference between 123 and 0123 in c?
What are pointers? What are different types of pointers?
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
Does free set pointer to null?