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 / poorni
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,temp=0,n,pos=0,element;
//clrscr();
printf("Search an Element in Array\n");
printf("Enter the number of elements: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the value for elements: ");
scanf("%d",&a[i]);
}
printf("Enter the searching element: ");
scanf("%d",&element);
for(i=0;i<n;i++)
{
if(a[i]==element)
{
temp=1;
pos=i;
}
}
if (temp==1)
printf("Element found %d , position=%
d",element,pos);
else
printf("Element not found\n");
getch();
}
| Is This Answer Correct ? | 56 Yes | 31 No |
Post New Answer View All Answers
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
Can we increase size of array in c?
A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile
What is the benefit of using const for declaring constants?
Write a simple code fragment that will check if a number is positive or negative.
What is a char c?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;
What is the purpose of the statement: strcat (S2, S1)?
What is a stream in c programming?
What is the right way to use errno?
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....
What is meant by initialization and how we initialize a variable?