fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int soat(int *a,int c){
  4. int i,j,k;
  5. for(i=0;i<c;i++){
  6. for(j=i+1;j<c;j++){
  7. if(a[i]>a[j]){
  8. k=a[i];
  9. a[i]=a[j];
  10. a[j]=k;
  11.  
  12. }
  13. }
  14. }
  15. }
  16.  
  17. int main(void) {
  18. int *a;
  19. int b,d;
  20. int c;
  21.  
  22. scanf("%d %d",&c,&b);
  23. a = (int *)malloc(sizeof (int) *c);
  24. for(d=0;d<c;d++){
  25. scanf("%d",&a[d]);
  26. }
  27. soat(a,c);
  28.  
  29. printf("%d",a[b]);
  30. free(a);
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5320KB
stdin
8 5
12 22 1 2 7 99 21 4
stdout
21