forked from Prajwal-061/Some-C-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorting and searching [0019].c
76 lines (62 loc) · 1.22 KB
/
sorting and searching [0019].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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
int sorting(int arr[], int n )
{
int temp;
int i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
return 0;
}
int search(int arr[],int key,int n)
{
int i;
for(i=0;i<n;i++)
{
if(key==arr[i])
{
return 1;
}
}
return -1;
}
int main()
{
int arr[50]={12,45,12,3,89,21,56,90,24,67};
int i,n=10;
printf(" the values in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n\n");
sorting(arr,n);
printf(" the sorted values in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n\n");
int key;
printf("Enter the value you want to search in an array: ");
scanf("%d",&key);
int result = search(arr,key,n);
if(result==1)
{
printf("%d is present in the array ", key);
}
else
{
printf("%d is not present in the array ", key);
}
return 0;
}