Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROWS 5
- #define COLS 5
- //naiti col with most zeros, reverse that col
- //not happy about reverse_col. should use 1D array, tryed to do it, but was only able to use 2D array, not 1D.
- //have to figure out/learn syntaxis
- //в двумерном массиве найти колонку с наибольшим количеством 0, перевернуть эту колонку
- //решила, но плохо, что последняя функция берет аргументом не столбец, а 2Д массив - переделать!
- void pop_arr(int r,int c,int a[r][c]);
- void pr_arr(int r,int c,int a[r][c]);
- int col_zero(int r,int c,int a[r][c]);//finds row with most zeros
- void reverse_col(int r,int c,int a[r][c],int n);
- int main()
- {
- int i,j,num,a[ROWS][COLS]={1,2,3,4,5, 6,7,0,8,9, 10,11,0,12,13, 14,15,0,16,17, 18,19,20,21,22};
- //pop_arr(ROWS,COLS,a);
- pr_arr(ROWS,COLS,a);
- num= col_zero(ROWS,COLS,a);
- printf("MOST zeros are in %d column, we will reverse it!\n",num);
- reverse_col(ROWS,COLS,a,num);
- pr_arr(ROWS,COLS,a);
- return 0;
- }
- void pop_arr(int r,int c,int a[r][c])
- {
- int i,j;
- for(i=0;i<r;i++)
- {
- for(j=0;j<c;j++)
- a[i][j]= rand()%5-2;
- }
- }
- void pr_arr(int r,int c,int a[r][c])
- {
- int i,j;
- for(i=0;i<r;i++)
- {
- for(j=0;j<c;j++)
- printf("%d\t",a[i][j]);
- printf("\n");
- }
- //printf("\n");
- }
- int col_zero(int r,int c,int a[r][c])//all about zero counting in each column
- {
- int i,j,current,total,index =0;
- total = 0;
- for(j=0;j<c;j++)
- {current = 0;//counts zeros in particular column
- for(i=0;i<r;i++)
- {
- if(a[i][j]==0)
- current++;
- }
- if(current > total)
- total = current,index=j;
- //printf("current %d total %d index %d\n",current,total,index);
- }
- return index;
- }
- void reverse_col(int r,int c,int a[r][c],int n)
- {
- int temp,i,j = 0;
- for(i=0;i<r/2;i++)
- {
- temp = a[i][n];
- a[i][n] = a[r-i-1][n];
- a[r-i-1][n] = temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement