Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


wite a programme in c to linear search a data using flag and
without using flags?

Answers were Sorted based on User's Feedback



wite a programme in c to linear search a data using flag and without using flags?..

Answer / ruchi

#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,a[15],num;
printf("\nHow many elements are there ");
scanf("%d",&n);
printf("\nEnter the elements ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the element do you want to search ");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
printf("\nElement is present ");
break;
}
else if((a[i]!=num)&&(i==n-1
))
{
printf("\nElement is not present");
}
}
getch();
}

Is This Answer Correct ?    19 Yes 8 No

wite a programme in c to linear search a data using flag and without using flags?..

Answer / st0le

int linearSearch(int a[],int ub,int key)
{
for(int i=0;i<n;i++)
if(a[i] == key) return i;
return -1; //not found!
}

int linearSearch(int a[],int ub,int key)
{
int flag = 0;
for(int i=0;i<n;i++)
if(a[i] == key)
{ flag = 1; break; }

return (flag)? i:-1; //not found!
}

Is This Answer Correct ?    7 Yes 0 No

wite a programme in c to linear search a data using flag and without using flags?..

Answer / st0le

sorry, abt the typho in the previous post...

"ub" shud be "n"...

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Interview Questions

Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child

10 Answers   IBM, Infosys,


What is structure padding ?

3 Answers   HP,


what is the use of #pragma pack, wer it is used?

2 Answers   Wipro,


What is the use of getchar() function?

0 Answers  


can we change the default calling convention in c if yes than how.........?

0 Answers   Aptech,


sum of two integers values only other then integer it should print invalid input.

1 Answers  


wap in c to accept a number display the total count of digit

4 Answers  


How would you use the functions fseek(), freed(), fwrite() and ftell()?

0 Answers   Aspire, Infogain, TISL,


Explain a pre-processor and its advantages.

0 Answers  


What is restrict keyword in c?

0 Answers  


Write a C program to fill a rectangle using window scrolling

1 Answers  


Differentiate between a structure and a union.

0 Answers   Zensar,


Categories