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                      
tip   SiteMap shows list of All Categories in this site.
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
how to find the kth smallest element in the given list of
array elemnts.
 Question Submitted By :: Phani_sravani
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to find the kth smallest element in the given list of array elemnts.
Answer
# 1
#include <stdio.h>
#include<conio.h>
main()
{
int a[20], i,n;
printf("ent how many elements u want to enter");
scanf("%d",&n);
printf("enter the elements");
for(i=1;i<=n;i++)
scanf("%d",&a[i]));
s=a[1];
for(i=2;i<=n;i++)
{
if
{
s>a[i]
s=a[i]
}
}
printf("the smallest element is %d",s);
}

hope this correct if it is wrong plz let me know
 
Is This Answer Correct ?    7 Yes 8 No
Shil
 
  Re: how to find the kth smallest element in the given list of array elemnts.
Answer
# 2
first the given list must be sorted using any of the 
sorting tecniques and then taking the kth element in that 
resultent array will give the answer 
                or
     another tecnique is using quick sort it will be easier 
and time complexity is also very less.sorry i dont have 
enough time to write the program here dontmind
 
Is This Answer Correct ?    6 Yes 2 No
Jyothi
 
 
 
  Re: how to find the kth smallest element in the given list of array elemnts.
Answer
# 3
sorting is not required in this case.u can still use same 
technique(not exactly) as mentioned in Cormen.an algorithm 
named "QuickSelect" which has an average complexity of      
O(nlong(n)).
Anyways to reduce the number of comparisions one can use 
tournament algorithm and for kth element we have to 
recursively go through the loosers list.
 
Is This Answer Correct ?    4 Yes 0 No
Newclient
 
  Re: how to find the kth smallest element in the given list of array elemnts.
Answer
# 4
#include<stdio.h>
#include<conio.h>
int main()
{
    int a[10],i,j,n,temp;
    printf("\nEnter the number of elements int he array ");
    scanf("%d",&n);
    printf("\nEnter the elements ");
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
                    for(j=i+1;j<n;j++)
                    {
                                      if(a[i]>a[j])
                                      {
                                                   temp=a[i];
                                                   a[i]=a[j];
                                                   a[j]=temp;
                                      }
                    }
    }
   printf("\nThe smallest element is "); 
    for(i=0;i<n;i++)
    {
                    printf("%d\n",a[i]);
                   break;            
    }  
                    getch();
}
 
Is This Answer Correct ?    0 Yes 7 No
Ruchi
 
  Re: how to find the kth smallest element in the given list of array elemnts.
Answer
# 5
int kmin(int a[],int n,int k)
{
int i;
int j;
int l;
int u;
int x;
int t;
l=1;
u=n;
	while(l<u)
	{
	i=l;
	j=u;
	x=a[k];
		while((i<=k)&&(j>=k))
		{
		while(a[i]<x) i++;
		while(a[j]>x) j--;
		swap(a[i],a[j]);
		i++;
		j--;
		}
	if(j<k) l=i;
	if(i>k) u=j;
	}
return(a[k]);
}
 
Is This Answer Correct ?    2 Yes 0 No
Khaja Moulali Shiak
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
WHAT IS MAXIMUM SIZE OF AN ARRAY IN C LANGUAGE? IBM5
Write the program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures. Google3
helllo sir , what is the main use of the pointer ,array ,and the structure with the example of a programe  2
Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..??? TCS1
#define f(x) main() { printf("\n%d",f(2+2)); }  3
What is the real difference between arrays and pointers?  11
for(i=0;i=printf("Hello");i++); printf("Hello"); how many times how will be printed?????????  4
what is diff b/w huge & far & near pointer?? HCL1
Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV Accenture3
Software Interview Questions CAT1
how to return 1000 variables from functio9n in c?plz give me code also  5
main is a predefined or user define function if user defined why? if predefined whay? TCS2
Write a program to compare two strings without using the strcmp() function Accenture14
how many times of error occur in C  7
how to find out the biggest element (or any other operation) in an array which is dynamic. User need not to mention the array size while executing.  2
a=0; while(a<5) printf("%d\n",a++); how many times does the loop occurs? a.infinite b.5 c.4 d.6 TCS5
which of the following go out of the loopo if expn 2 becoming false a.while(expn 1){...if(expn 2)continue;} b.while(!expn 1){if(expn 2)continue;...} c.do{..if(expn 1)continue;..}while(expn 2); d.while(!expn 2){if(expn 1)continue;..} TCS2
plz answer....A program that takes 3 variables e.g a,b,c in as seperate parameters and rotates the values stored so that value goes a to b, b to c and c to a .  3
int *a[5] refers to TCS8
I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.  1
 
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