forked from Haresh1204/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kth_small_element.c
44 lines (42 loc) · 926 Bytes
/
kth_small_element.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
void sorting(int *arr, int size){
int temp, sorted = 0;
for (int i = 0; i < size - 1; i++){
for (int j = 0; j < size - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
void cal(int* arr,int size,int data){
sorting(arr,size);
for (int i = 0; i < size; i++)
{
if (arr[i]==data)
{
printf("R : %d",arr[i]);
break;
}
}
}
int main(int argc, char const *argv[]){
int size,data;
printf("Enter Size : ");
scanf("%d",&size);
int arr[size];
printf("Enter Array Elements: ");
for (int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
printf("Data : ");
scanf("%d",&data);
cal(arr,size,data);
return 0;
}