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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between array and pointer in c?

582


Explain what is meant by 'bit masking'?

646


What is union and structure?

577


Can you write a programmer for FACTORIAL using recursion?

618


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1881






Write a program to identify if a given binary tree is balanced or not.

689


Explain what is wrong with this statement? Myname = ?robin?;

1043


What are different types of variables in c?

573


Explain argument and its types.

608


write a program to find out prime number using sieve case?

1646


What is the general form of function in c?

615


What are data structures in c and how to use them?

682


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

1677


Can we replace the struct function in tree syntax with a union?

785


What are register variables? What are the advantage of using register variables?

689