-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path331.c
45 lines (40 loc) · 799 Bytes
/
331.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
// Write a program in C to sort an array using Pointer and functions both. Atleast one Argument to the function should be a pointer.
#include<stdio.h>
int i=0;
void print(int a[],int n)
{
for ( i = 0; i < n; i++)
{
printf("%d\n",*(a+i));
}
}
void sort(int *arr,int n)
{int k;
for (size_t i = 0; i < n; i++)
{
for (size_t j = i+1; j < n; j++)
{
if (arr[i]>arr[j])
{
k=arr[i];
arr[i]=arr[j];
arr[j]=k;
}
}
}
}
int main()
{
int n;
printf("number of elements of the array\n");
scanf("%d",&n);
int arr[n];
for (size_t i = 0; i < n; i++)
{
printf("enter the value of %d element\n",i+1);
scanf("%d",&arr[i]);
}
sort(arr,n);
print(arr,n);
return 0;
}