Computer Science, asked by REDBALLZ8224, 10 months ago

A double Dimensinal array us defined as N[4][4] to store numbers write a program to find the sum of all even numbers and product of all odd numbers of the elements stored in double dimensional array

Answers

Answered by proforty7
1

Answer:

#include<iostream>

using namespace std;

int main() {

 int n[4][4];

 for(int i=0; i<4; i++) {

   for(int j=0; j<4; j++) {

     cin >> n[i][j];

   }

 }

 long even = 0, odd = 1;

 for(int i=0; i<4; i++) {

   for(int j=0; j<4; j++) {

     // If number is even

     if (n[i][j] % 2 == 0) {        

       even += n[i][j];

     } else {

       // If number is odd

       odd *= n[i][j];

     }

   }

 }

 cout << "Odd product: " << odd << "; Even sum: " << even << endl;

 return 0;

}

Explanation:

Similar questions