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

In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

0 Answers  


what is ANSI and ISO

7 Answers   HCL,


What is a ternary operator in c?

0 Answers  


What is a pointer value and address in c?

0 Answers  


Differentiate abs() function from fabs() function.

0 Answers  






pick out the odd one out of the following a.malloc() b.calloc() c.free() d.realloc()

2 Answers   TCS, ZenQ,


int x=5; printf("%d%d%d",x,x<<2,x>>2);

2 Answers   TANCET,


How can I sort a linked list?

0 Answers  


Why is conio.h not required when we save a file as .c and use clrscr() or getch() ?

2 Answers  


int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above

0 Answers  


write a c program to find largest of three numbers using simple if only for one time.

1 Answers  


Write a code of a general series where the next element is the sum of last k terms.

0 Answers   Aspiring Minds,


Categories