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?
Answers were Sorted based on User's Feedback
Answer / nikhil srivastav (mca pesit b
int search(int *arr,int item,int arr_size)
{
int i;
for(i=0;i<arr_size;i++)
{
if(item==*(arr+i))
return i;
}
return -1;
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / p govind rao
#include<stdlib.h>
#include<stdio.h>
#define Max 6
int fun_rev(int *ptr, int num)
{
int i=0;
while(i<=Max)
{
if(num==*ptr)
{
return 1 ;
}
else
{
return 0;
}
i++;
ptr++;
}
}
int main()
{
int arr[Max]={3,4,5,6,2,1};
int item=6,result;
result=fun_rev(arr,item);
printf("result = %d",result);
return 0;
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / 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 |
Explain the meaning of keyword 'extern' in a function declaration.
write a program to fined second smallest and largest element in a given series of elements (without sorting)
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)
What is huge pointer in c?
How can I read a directory in a c program?
Difference between for loop and while loop?
What is the advantage of an array over individual variables?
Can i use “int” data type to store the value 32768? Why?
When should the volatile modifier be used?
WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents?
6 Answers Finite Infotech, Lovely Professional University, Wipro,
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
write a own function for strstr