Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int n, m; // broj na redici i na koloni
- scanf("%d%d", &n, &m);
- int matrica[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- scanf("%d", &matrica[i][j]);
- }
- }
- int suma = 0;
- int proizvod = 1;
- for(int i = 0; i < n; i++) {
- suma += matrica[i][i]; // glavna dijagonala
- proizvod *= matrica[i][n - 1 - i]; // sporedna dijagonala
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(matrica[i][j] % 2 == 0) { // paren broj
- matrica[i][j] = suma;
- }
- else { // neparen broj
- matrica[i][j] = proizvod;
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- printf("%d ", matrica[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
- /*
- 4 4
- 1 2 3 4
- 5 6 7 8
- 9 10 11 12
- 13 14 15 16
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement