Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROWS 5
- #define COLS 10
- void pop_arr(int r,int c,int a[r][c]);
- void pr_arr(int r,int c,int a[r][c]);
- void manipulate_arr(int r,int c,int a[r][c]);
- int is_it_neven(int *val);
- //https://otvet.mail.ru/question/211934162
- //more logical, maybe, just to compare two neighboring rows by noneven elements
- //counter, and switch them, if order is wrong
- //i don't know syntaxys of passing row(out of 2D array)into function
- //if i to calculate neven elements in all rows instead, once i switch two
- //rows, that calulation stops making sense, as order will be different
- //otherwise i need different containers to keep in every row of 2D array
- //additional element, which contains counter of non even elements in row
- //THAT zadacha is quite misleading, it forces me to think in wrong direction first!
- //SOMETIME, LIKE 10 days ago i had the same dilemma, just left it as it was
- //and totally forgot about it, can;t even think about what was that zadacha i got
- //stuck with
- //poka proga beret po 1 elementu stroki, proverjaet, esli on nechetnyj - summiruet!
- //xochu, htob brala vsju stroku, i odnim maxom proverjala!
- int main()
- {
- int i,j,k,l, arr[ROWS][COLS],counter[ROWS];
- pop_arr(ROWS,COLS,arr);
- pr_arr(ROWS,COLS,arr);
- if(is_it_neven(&arr[0][3]))
- printf("it's even number!");
- //calculates how many non even numbers contains each row
- for(i=0;i<ROWS;i++)
- {
- counter[i]=0;
- for(j=0;j<COLS;j++)
- {
- if(is_it_neven(&arr[i][j]))//esli nechetnoe?
- (counter[i])++;
- }
- }
- //print how many non even numbers contains each row
- for(i=0;i<ROWS;i++)
- {
- printf("%d st row contains %d non even numbers\n",i,counter[i]);
- }
- 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()%20;
- }
- }
- }
- 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");
- }
- }
- int is_it_neven(int *val)
- {
- return (*val%2)? 1:0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement