-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprac12.c
More file actions
36 lines (33 loc) · 680 Bytes
/
prac12.c
File metadata and controls
36 lines (33 loc) · 680 Bytes
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
//sort int array using pointer
#include<stdio.h>
void arrsort(int *arr,int n);
int main(){
int n;
printf("Enter n:");
scanf("%d", &n);
int arr[n];
for(int i=0;i<n;i++){
scanf("%d", &arr[i]);
}
int *ptr=arr;
arrsort(ptr,n);
for(int i=0;i<n;i++){
printf("%d ", arr[i]);
}
}
void arrsort(int *arr,int n){
int temp,x;
for(int i=0;i<n;i++){
temp=*(arr+i);
for(int j=0;j<i+1;j++){
if(temp>=*(arr+j)){
x=temp;
temp=*(arr+j);
*(arr+j)=x;
}
if(temp<*(arr+j)){
*(arr+i)=temp;
}
}
}
}