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 / sharan
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i;
int ele,temp=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
// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
printf("Element found %d , position=%d\n",ele,i);
}
}
if (!temp)
printf("Element not found\n");
} // end of main()
| Is This Answer Correct ? | 149 Yes | 97 No |
Post New Answer View All Answers
What is the purpose of macro in C language?
Is a house a mass structure?
Which built-in library function can be used to match a patter from the string?
What is the main difference between calloc () and malloc ()?
Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff
Why shouldn’t I start variable names with underscores?
Explain what are run-time errors?
What is C language ?
What is a char c?
Why is structure important for a child?
Explain what are compound statements?
Why c language is called c?
Should a function contain a return statement if it does not return a value?
What is variable in c example?
Explain what are its uses in c programming?