-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzoho_array.c
42 lines (42 loc) · 904 Bytes
/
zoho_array.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
#include<stdio.h>
void sort(int* a,int n){
//bubble sort
//i/p : *a - array is passed as reference && n -no of terms
int temp,i,j;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(a[i] < a[j]){
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
int main(){
int a[10],n,i,cnt_var,l=0,m;// l -> to points the first element in array
printf("Enter the n terms : ");
scanf("%d",&n);
printf("Enter the array elements : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
//call sort function to sort the array (! array is passed as reference )
sort(&a,n);
//cnt_var -> control variable of the loop
cnt_var=0;
//m -> to points the last position in array
m=n-1;
//logic is for every even number if stmt is executed
//odd number -> else stmt is executed
while(cnt_var < n){
if((cnt_var%2) == 0){
printf("%d\t",a[m]);
m--;
}else{
printf("%d\t",a[l]);
l++;
}
cnt_var++;
}
return 0;
}