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
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
differentiate built-in functions and user – defined functions.
Explain that why C is procedural?
What are pragmas and what are they good for?
What is dynamic dispatch in c++?
Why #include is used in c language?
Explain what is the general form of a c program?
What are local variables c?
What is a char in c?
what do you mean by inline function in C?
which type of aspect you want from the student.
hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...
to find the closest pair
What is c standard library?
Why doesnt long int work?