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

how many key words availabel in c a) 28 b) 31 c) 32

0 Answers  


What is a pointer?

1 Answers   ADP, IFFCO,


What is a substring in c?

0 Answers  


how to impliment 2 or more stacks in a single dimensional array ?

1 Answers   iFlex, Microsoft,


What is the purpose of sprintf?

0 Answers  






write a program to display all prime numbers

0 Answers  


Differentiate between ordinary variable and pointer in c.

0 Answers  


WRITE A C PROGRAM FOR PRINT "RHOMBUS" STRUCTURE . Example: Enter the numbers :3 * * * * * * * *

3 Answers   Infosys, TCS,


How can I find out how much free space is available on disk?

0 Answers  


what is the use of call back function in c?tell me with example

2 Answers   Bosch,


What does node * mean?

0 Answers  


WAP that prints the number from 1 to 100. but for multiplies of three print "XXX" instead of the number and for the multiplies of five print "YYY" . for number which are multiplies of both three and five print "ZZZ"

3 Answers  


Categories