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
#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }
What are the two types of structure?
What does %d do in c?
What happens if a header file is included twice?
What is the use of void pointer and null pointer in c language?
Explain how do you list files in a directory?
What is n in c?
What does s c mean in text?
Does c have enums?
Explain how can you check to see whether a symbol is defined?
a program that can input number of records and can view it again the record
How many levels of indirection in pointers can you have in a single declaration?
Is it fine to write void main () or main () in c?
What is difference between structure and union in c programming?
Explain what is a stream?