write a function that accepts an integer/char array and an
search item.If the search item is there in the array return
position of array and value else return -1.without using
other array,without sorting,not to use more than one loop?

Answers were Sorted based on User's Feedback



write a function that accepts an integer/char array and an search item.If the search item is there ..

Answer / nikhil srivastav (mca pesit b

int search(int *arr,int item,int arr_size)
{
int i;
for(i=0;i<arr_size;i++)
{
if(item==*(arr+i))
return i;
}
return -1;
}

Is This Answer Correct ?    2 Yes 0 No

write a function that accepts an integer/char array and an search item.If the search item is there ..

Answer / p govind rao

#include<stdlib.h>
#include<stdio.h>
#define Max 6

int fun_rev(int *ptr, int num)
{
int i=0;
while(i<=Max)
{
if(num==*ptr)
{
return 1 ;
}
else
{
return 0;
}
i++;
ptr++;
}
}

int main()
{
int arr[Max]={3,4,5,6,2,1};
int item=6,result;
result=fun_rev(arr,item);
printf("result = %d",result);
return 0;
}

Is This Answer Correct ?    2 Yes 0 No

write a function that accepts an integer/char array and an search item.If the search item is there ..

Answer / ashutosh tiwari

int find_num(int *arr, int *arr_num, int arr_size)
{
int i;
while((i<arr_size) && (*(arr+i) != *arr_num))
i++;
if(i >= arr_size)
return -1;
else
return i;
}

OR

int find_num(int *arr, int *arr_num, int arr_size)
{
int i;
for(i=0;i<arr_size;i++)
{
if(*(arr+i) != *arr_num)
continue;
else
return i;
}
return -1;
}

input to function will be actual array, number to be found
with its reference and array size
output will be -1 if fail otherwise number position

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C Interview Questions

12345 1234 123 12 1

2 Answers  


Explain the use of bit fieild.

0 Answers  


How do you initialize function pointers? Give an example?

3 Answers  


write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?

0 Answers  


WRITE A PROGRAM IN C TO MULTIPLY TWO 2-D ARRAYS

4 Answers  


Why shouldn’t I start variable names with underscores?

0 Answers  


Is there sort function in c?

0 Answers  


What is a far pointer?What is the utility?

4 Answers  


main() { printf("hello"); fork(); }

0 Answers   Wilco,


What is the use of header?

0 Answers  


Differentiate between a for loop and a while loop? What are it uses?

0 Answers   TISL,


What is the output of below code? main() { static int a=5; printf("%3d",a--); if(a) main(); }

1 Answers  


Categories