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 / mr. x
#include<stdio.h>
#include<conio.h>
void main ()
{
int a[5],b,c,i;
clrscr();
printf("
Enter no. of elements: ");
scanf("%d",&c);
i=0;
while(i<c)
{
scanf("%d",&a[i]);
i++;
}
printf("
Enter the elements to be searched: ");
scanf("%d",&b);
i=0;
while(i<c &b!=a[i])
{
i++;
}
if (i<c)
{
printf("number found");
i++;
}
else
{
printf(" number not found");
}
getch();
}
| Is This Answer Correct ? | 8 Yes | 5 No |
Post New Answer View All Answers
What is the use of ?: Operator?
How can I discover how many arguments a function was actually called with?
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
Which header file is essential for using strcmp function?
What is the difference between array and structure in c?
main() { printf("hello"); fork(); }
What is variable declaration and definition in c?
When should a type cast be used?
How many levels of pointers have?
Explain about the constants which help in debugging?
Difference between Shallow copy and Deep copy?
Why is sizeof () an operator and not a function?
In C language what is a 'dangling pointer'?
How to write a multi-statement macro?
What is a scope resolution operator in c?