logo

CuriousTab

CuriousTab

Discussion


Home Technical Questions Programming Comments

  • Question
  • Write a c program for linear search.


  • Correct Answer
  • #include int main(){ int a[10],i,n,m,c=0; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements of the array: "); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); for(i=0;i<=n-1;i++){ if(a[i]==m){ c=1; break; } } if(c==0) printf("The number is not in the list"); else printf("The number is found"); return 0; } Sample output: Enter the size of an array: 5 Enter the elements of the array: 4 6 8 0 3 Enter the number to be search: 0 The number is found 


  • Programming problems


    Search Results


    • 1. What will be output when you will execute following c code? #include void main() { switch(2) { case 1L:printf("No"); case 2L:printf("%s","I"); goto Love; case 3L:printf("Please"); case 4L:Love:printf("Hi"); } }

    • Options
    • A. I
    • B. IPleaseHi
    • C. IHi
    • D. Compilation error
    • Discuss
    • 2. What's the difference between the functions rand(), random(), srand() and randomize()?
    • Discuss
    • 3. What do the functions atoi(), itoa() and gcvt () do? Show how would you use them in a program.
    • Discuss
    • 4. Point out the error in the following program. main() { char mybuf[] = "Zanzibar" ; char yourbuf[] = " Zienckewiz"; char * const ptr = mybuf; *ptr = 'a'; ptr = yourbuf; }
    • Discuss
    • 5. What would be the output of the following program ? main() { const int x = 5; int *ptrx; ptrx = &x; *ptr = 10; printf ("%d", x); }

    • Options
    • A. 5
    • B. 10
    • C. Error
    • D. Garbage value
    • Discuss
    • 6. Rewrite the following set of statements using conditional operators. int a =1, b ; if ( a > 10 ) b = 20;
    • Discuss
    • 7. How many times the following program would print 'Jamboree'? main() { printf ( "\nJamboree"); main (); }
    • Discuss
    • 8. Macro flowchart is also called as

    • Options
    • A. Less Detail flowchart
    • B. More detail flowchart
    • C. Simple detailed flowchart
    • D. None of the above
    • Discuss
    • 9. public abstract interface Frobnicate { public void twiddle(String s); } Which is a correct class?

    • Options
    • A. public abstract class Frob implements Frobnicate { public abstract void twiddle(String s) { } }
    • B. public abstract class Frob implements Frobnicate { }
    • C. public class Frob extends Frobnicate { public void twiddle(Integer i) { } }
    • D. public class Frob implements Frobnicate { public void twiddle(Integer i) { } }
    • Discuss
    • 10. Convert the expression ((A + B) * C ? (D ? E) ^ (F + G)) to equivalent Prefix Notation
    • Discuss


    Comments

    There are no comments.

Enter a new Comment