ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2248)
 C++ interview questions  C++ Interview Questions (1106)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (644)
Question
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
 Question Submitted By :: Srinivas
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
#include<stdio.h>
#include<conio.h>

void main()
{
int a[5],i;
int ele,temp=0,pos=0;

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",&ele);

// searching for the element

for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
pos=i;
}
}

if (temp==1)
printf("Element found %d , position==%d",ele,pos);
else
printf("Element not found\n");
} // end of main()
 
Is This Answer Correct ?    366 Yes 95 No
Anuja Kulkarni
 
  Re: 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
# 2
#include<stdio.h>
#include<conio.h>

void main()
{
int a[5],i;
int ele,temp=0;

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",&ele);

// searching for the element

// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
printf("Element found %d , position=%d\n",ele,i);
}
}
if (!temp)
printf("Element not found\n");
} // end of main()
 
Is This Answer Correct ?    115 Yes 70 No
Sharan
 
 
 
  Re: 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
# 3
why should we mention temp=something ..... wat is temp here
plz explain
 
Is This Answer Correct ?    48 Yes 37 No
Kirlosky
 
  Re: 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
# 4
#include<stdio.h>
#include<conio.h>

void main()
{
int a[5],i;
int ele,temp=0,pos=0;

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",&ele);

/* searching for the element*/

for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
pos=i;
}
}

if (temp==1)
printf("Element found %d , position==%d",ele,pos);
else
printf("Element not found\n");
}
 
Is This Answer Correct ?    62 Yes 32 No
Bishwas Bidari
 
  Re: 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
# 5
#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 ?    38 Yes 16 No
Poorni
 
  Re: 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
# 6
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 ?    14 Yes 26 No
Jamshed
 
  Re: 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
# 7
#include<stdio.h> 
Is This Answer Correct ?    10 Yes 29 No
All
 
  Re: 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
# 8
#include<stdio.h>
#include<conio.h>
void searchval(int a[5],int n)
{
int i,temp=0,pos=0;

for (i=0; i<5; i++)
{
// printf("value of array:: %d",i);
if (a[i]==n)
{
temp=1;
pos=i;
}
}
if (temp==1)
{

printf("Element found %d , position==%d",n,pos);
}
else
{
printf("Element not found\n");
}




}
void main()
{
int a[5],i,n;
int ele,pos,temp;

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",&ele);

searchval(a,ele);
getch();
}
 
Is This Answer Correct ?    17 Yes 10 No
Sunil Makwana
 
  Re: 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
# 9
#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 ?    17 Yes 15 No
Vs
 
  Re: 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
# 10
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 ?    21 Yes 12 No
Kapil Hansrajani
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program that finds the factorial of a number using recursion? TATA 13
main() { float a=3.2e40; printf("%d",a); } Satyam 9
A B C D E F G F E D C B A A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A   2
main() { int i; printf("%d",i^i); }   1
main() { int a=0; if(a=0) printf("Ramco Systems\n"); printf("India\n"); } output? Ramco 7
write a program to copy a string without using a string?   2
main() { float f1=10.5; double db1=10.5 if(f1==db1) printf("a"); else printf("b") } CSC 2
what is the output of the following program? #include<stdio.h> void main() { float x=1.1; while(x==1.1) { printf("\n%f",x); x=x-0.1; } }   6
int a[3][5]={ {1,2,3,4,5],{2,3,4,5,6},{10,11,12,13,14}}; int *p=&a; printf(%d,*(*(x+1)+3)); Wipro 2
what is the different between if-else and switch statment (other than syntax) CTS 25
I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.   1
Write a program to print this triangle: * ** * **** * ****** * ******** * ********** Don't use printf statements;use two nested loops instead. you will have to use braces around the body of the outer loop if it contains multiple statements. Wipro 6
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com