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 / kapil hansrajani
include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,n;
clrscr();
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element to search : ");
scanf("%d",&j);
for(i=0;i<n;i++)
{
if(a[i]==j)
{
printf("The position of the element %d is %d ",j,i);
break;
}
}
getch();
}
| Is This Answer Correct ? | 48 Yes | 26 No |
Post New Answer View All Answers
How main function is called in c?
How can I do graphics in c?
What does sizeof int return?
Explain what are the standard predefined macros?
How can I determine whether a machines byte order is big-endian or little-endian?
What is the use of a conditional inclusion statement in C?
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is c language & why it is used?
What is the difference between variable declaration and variable definition in c?
What is meant by realloc()?
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
How can a string be converted to a number?
What is the purpose of 'register' keyword?
What are the features of c languages?
Between macros and functions,which is better to use and why?