ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
wite a programme in c to linear search a data using flag and
without using flags?
 Question Submitted By :: Misbah
I also faced this Question!!     Rank Answer Posted By  
 
  Re: wite a programme in c to linear search a data using flag and without using flags?
Answer
# 1
#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 ?    4 Yes 1 No
Ruchi
 
  Re: wite a programme in c to linear search a data using flag and without using flags?
Answer
# 2
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 ?    0 Yes 0 No
St0le
 
 
 
  Re: wite a programme in c to linear search a data using flag and without using flags?
Answer
# 3
sorry, abt the typho in the previous post...

"ub" shud be "n"...
 
Is This Answer Correct ?    0 Yes 0 No
St0le
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
how to make program without <> in library. ADITI1
Which of the following sorts is quickest when sorting the following set: 1 2 3 5 4 1) Quick Sort 2) Bubble Sort 3) Merge Sort  5
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+.... Ignou2
I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?  3
1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a sorted list of array? Qualcomm2
Can u return two values using return keyword? If yes, how? If no, why?  7
i want to have a program to read a string and print the frequency of each character and it should work in turbo c  2
WRITE A C PROGRAM TO FIND SECOND BIGGEST VALUE FROM THE GIVEN VALUES  1
Which of the following are valid "include" formats? A)#include and #include[file.h] B)#include (file.h) and #include C)#include [file.h] and #include "file.h" D)#include <file.h> and #include "file.h" Accenture14
where does malloc() function get the memory?  1
write a function for strtok()?? Verifone1
Reverse the part of the number which is present from position i to j. Print the new number. eg: num=789876 i=2 j=5 778986  1
what is the use of pointers  5
HOW TO HANDLE EXCEPTIONS IN C  5
declare afunction pointer to int printf(char *)? HCL1
the code is::::: if(condition) printf("hello"); else printf("world"); WHAT WILL BE THE CONDITION IN IF IN SUCH A WAY THAT BOTH HELLO AND WORLD ARE PRINTED IN A SINGLE ATTEMPT?????? SINGLE ATTEMPT IN THE SENSE... IT MUST FIRST PRINT "HELLO" AND IT MUST GO TO ELSE PART AND PRINT "WORLD"..... NO LOOPS, RECURSION ARE ALLOWED........................ IBM9
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.  4
sir, i cannot find the way how to write aprogram by using array on queue IISIT1
We can draw a box in cprogram by using only one printf();& without using graphic.h header file? NIIT3
what is array? HCL22
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com