-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcprog012.c
More file actions
42 lines (42 loc) · 824 Bytes
/
cprog012.c
File metadata and controls
42 lines (42 loc) · 824 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
37
38
39
40
41
42
#include<string.h>
#include<math.h>
#include<stdio.h>
int fun2(int a[], int n, int b[],int c[])
{
/**/
int i=0,j=0,t=0,num=0,x;
for(;i<n;i++) if (a[i]>(-20)){b[j]=a[i];num++;j++;}
for(i=0;i<n;i++) c[i]=b[i];
for(i=0;i<n;i++){
x=i;
for(j=i+1;j<num;j++) if(c[x]>c[j]) x=j;
if(x!=i){
t=c[i];
c[i]=c[x];
c[x]=t;
}
}
return num;
/**/
}
void main()
{
int n = 10,i,nb;
int aa[10] = {12, -10, -31, -18, -15, 50, 17, 15, -20, 20};
int bb[10],cc[10];
printf("There are %2d elements in aa.\n ",n);
printf("They are: ");
for(i=0; i<n; i++)
printf("%6d",aa[i]);
printf("\n");
nb=fun2(aa,n,bb,cc);
printf("Elements in bb are:");
for(i=0; i<nb; i++)
printf("%6d",bb[i]);
printf("\n");
printf("Elements in cc are:");
for(i=0; i<nb; i++)
printf("%6d",cc[i]);
printf("\n");
printf("There are %2d elements in bb.\n",nb);
}