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
What is the difference between array and pointer in c?
Explain what is meant by 'bit masking'?
What is union and structure?
Can you write a programmer for FACTORIAL using recursion?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
Write a program to identify if a given binary tree is balanced or not.
Explain what is wrong with this statement? Myname = ?robin?;
What are different types of variables in c?
Explain argument and its types.
write a program to find out prime number using sieve case?
What is the general form of function in c?
What are data structures in c and how to use them?
write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?
Can we replace the struct function in tree syntax with a union?
What are register variables? What are the advantage of using register variables?