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
Answers were Sorted based on User's Feedback
Answer / e v n raja
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,ele;
clrscr();
printf("enter the array elements
");
for (i=0; i<5; i++)
scanf("%d",&a[i]);
printf("Enter the element to be search
");
scanf("%d",&ele);
// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==ele)
{
printf("Element found %d , position==%d",ele,i);
break;
}
}
} // end of main()
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / laxmi
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5]={1,2,3,4,5};
int i;
clrscr();
printf("
enter the value");
scanf("%d",&i);
for(i=0;i<5;i++)
if(i<5)
{
printf("
the value is present=%d");
}
else
{
printf("
the value is absent=%d");
}
getch();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vs
#include<stdio.h>
#include<conio.h>
void main()
int a[5],i;
int e,t=0,p=0;
clrscr();
printf("enter the array of elements/n");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
clrscr();
printf("enter the element to search/n");
scanf("%d",&e);
for(i=0;i<5;i++)
{
if(a[i]==e)
{
t=1;
p=i;
}
}
if(t==1)
printf("element found--%d/n position--%d",e,p);
else
printf("element not found/n");
getch();
}
| Is This Answer Correct ? | 21 Yes | 22 No |
Answer / aishwarya rajan
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,a[30];
char item;
cout<<"Enter the number of elements you would like to enter in the array: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the element"<<i+1<<" :";
cin>>a[i];
}
cout<<"Enter the element you are searching for in the array:";
cin>>item;
if(a[i]==item)
cout<<"The item does exist in the array!! it is the "<<i+1<<" element!!";
else
cout<<"The item is not found in the array!!";
getch();
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / priya chauhan
Find the presence of a given number in a set of numbers
using array. also find the position of the number.
| Is This Answer Correct ? | 5 Yes | 8 No |
Answer / jamshed
IF WE STORE ELEMENTS IN AN ARRAY :
import java.io.*;
class Search
{
public static void main()throws IOException
{
InputStreamReader isr=new
InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int a[]={5,7,9,11,15,20,30,45,89,97};
int i,n,c=0;
System.out.println("Enter a Number to Search");
n=Integer.parseInt(br.readLine());
for(i=0;i<a.length;i++)
{
if(a[i]==n)
{
c++;
System.out.println("\nThe Number "+n+"
Does Exist");
System.out.println("The Position is
"+(i+1));
}
}
if(c==0)
System.out.println("Search Element Not Found");
}
}
| Is This Answer Correct ? | 18 Yes | 27 No |
two progs are given. one starts counting frm 0 to MAX and the other stars frm MAX to 0. which one executes fast.
What is the size of empty structure in c?
which is the best site or book for learning C...and i need the content for C..how to get the good programming skills....? can plz suggest me....
Study the Following Points: a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static 1. Which of the Following Statements are true w.r.t Bit- Fields A)a,b&c B)Only a & b C)Only c D)All
20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer:??????
WAP to accept first name,middle name & last name of a student display its initials?
Tell me when is a void pointer used?
what is C?
Write a program to accept a character & display its corrosponding ASCII value & vice versa?
Write a simple program to find the size of different basic data types in C.
How do you search data in a data file using random access method?
Explain what is the most efficient way to store flag values?