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 difference between main and void main?

614


what are the facialities provided by you after the selection of the student.

1648


What is the use of parallelize in spark?

566


Can include files be nested? How many levels deep can include files be nested?

648


What is meant by initialization and how we initialize a variable?

577






Why do some versions of toupper act strangely if given an upper-case letter?

622


How do you list files in a directory?

553


The file stdio.h, what does it contain?

653


What are pointers in C? Give an example where to illustrate their significance.

737


What is the translation phases used in c language?

621


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1457


Write a C program to count the number of email on text

1406


Can you pass an entire structure to functions?

685


In c language can we compile a program without main() function?

566


Explain can you assign a different address to an array tag?

632