Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //void alloc_mem(int **mt, int m, int n){
- // mt = new int*[m];
- // for(int i = 0; i < m; i++)
- // mt[i] = new int [n];
- //}
- void free_mem(int **mt, int m, int n){
- for(int i = 0; i < m; i++)
- delete[] mt[i];
- delete[] mt;
- }
- void input(int **mt, int m, int n){
- for(int i = 0; i < m; i++)
- for(int j = 0; j < n; j++){
- printf("mt[%d][%d] = ", i, j);
- scanf("%d", &mt[i][j]);
- }
- }
- void output(int **mt, int m, int n){
- for(int i = 0; i < m; i++){
- for(int j = 0; j < n; j++)
- printf("%d ", mt[i][j]);
- printf("\n");
- }
- }
- int xuly(int **mt, int m, int n){
- int tong = 0;
- for(int i = 0; i < m; i++)
- for(int j = 0; j < n; j++)
- tong += mt[i][j] % 2 == 0? mt[i][j]:0;
- return tong;
- }
- int main(){
- int m, n, **mt;
- printf("Nhap m, n = ");
- scanf("%d%d", &m, &n);
- //alloc_mem(mt, m, n);
- mt = new int*[m];
- for(int i = 0; i < m; i++)
- mt[i] = new int [n];
- input(mt, m, n);
- output(mt, m, n);
- printf("Tong cac phan tu chan la %d", xuly(mt, m, n));
- free_mem(mt, m, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment