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 / ghost
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,element,temp,pos;
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",&element);
// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==element)
{
temp=1;
pos=++i;
}
}
if (temp==1)
printf("%d Element found at position==%d",element,pos);
else
printf("Element not found\n");
getch();
} // end of main()
| Is This Answer Correct ? | 13 Yes | 12 No |
Post New Answer View All Answers
How do c compilers work?
Can a local variable be volatile in c?
What is pointers in c?
State the difference between realloc and free.
What does the format %10.2 mean when included in a printf statement?
The __________ attribute is used to announce variables based on definitions of columns in a table?
What is typedef example?
What does & mean in scanf?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.
What is the use of typedef in structure in c?
What is clrscr in c?
Explain the difference between malloc() and calloc() in c?
List the different types of c tokens?