wite a programme in c to linear search a data using flag and
without using flags?
Answers were Sorted based on User's Feedback
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 |
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 |
Answer / st0le
sorry, abt the typho in the previous post...
"ub" shud be "n"...
Is This Answer Correct ? | 1 Yes | 2 No |
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
Convert the following expression to postfix and prefix (A+B) * (D-C)
Explain what is wrong with this statement? Myname = ?robin?;
Explain main function in c?
How do I round numbers?
Write a program that accept anumber in words
Is printf a keyword?
Write a progarm to find the length of string using switch case?
What is function definition in c?
What is conio h in c?
What is the use of a ‘