Last active
December 26, 2015 23:59
-
-
Save elleryq/7234777 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(int argc, char* argv[]){ | |
| int row=0, col=0; | |
| int i=0,j=0; | |
| int m=0,n=0; | |
| int tmp=0,sum=0; | |
| float avg=0; | |
| FILE* input=fopen("2d_ary.txt","r"); | |
| int **num=(int**)calloc(row,sizeof(int*)); | |
| int* vs=(int*)calloc(row,sizeof(int)); | |
| fscanf(input," %d %d", &row,&col); | |
| // printf("%d, %d\n", row, col); | |
| for(i=0;i<row;i++){ | |
| num[i]=(int*)calloc(col,sizeof(int)); | |
| for(j=0;j<col;j++){ | |
| fscanf(input,"%d", (num[i]+j)); | |
| } | |
| } | |
| /* for(i=0;i<row;i++){ | |
| for(j=0;j<col;j++){ | |
| printf("%d ", *(num[i]+j)); | |
| } | |
| printf("\n"); | |
| }*/ | |
| for(i=0;i<col;i++){ | |
| for(j=0;j<row;j++){ | |
| vs[j]=*(num[j]+i); | |
| } | |
| for(m=0;m<row;m++){ | |
| for(n=row-1;n>m;n--){ | |
| if(vs[n]<vs[n-1]){ | |
| tmp=vs[n-1]; | |
| vs[n-1]=vs[n]; | |
| vs[n]=tmp; | |
| } | |
| } | |
| } | |
| sum=0; | |
| avg=0; | |
| for(m=0;m<row;m++) | |
| sum+=vs[m]; | |
| avg=(float)sum/row; | |
| printf("column %d: minimum=%d, maximum=%d, average=%.4f\n", i+1, vs[0], vs[row-1], avg); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment