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 difference between main and void main?
what are the facialities provided by you after the selection of the student.
What is the use of parallelize in spark?
Can include files be nested? How many levels deep can include files be nested?
What is meant by initialization and how we initialize a variable?
Why do some versions of toupper act strangely if given an upper-case letter?
How do you list files in a directory?
The file stdio.h, what does it contain?
What are pointers in C? Give an example where to illustrate their significance.
What is the translation phases used in c language?
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
Write a C program to count the number of email on text
Can you pass an entire structure to functions?
In c language can we compile a program without main() function?
Explain can you assign a different address to an array tag?