Meseriasul

Suma numerelor pare din matrice.

Jan 23rd, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int i,j,a[50][50],m,n, s = 0;
  7.     cout<<"Nr de linii: ";   cin>>n;
  8.     cout<<"Nr de coloane: "; cin>>m;
  9.     for(i = 1; i <= n; i++){
  10.         for(j = 1; j <= m; j++){
  11.             cout<<"a["<<i<<"]["<<j<<"] = ";
  12.             cin>>a[i][j];
  13.         }
  14.     }
  15.  
  16.     for(i = 1; i <= n; i++){
  17.         for(j = 1; j <= m; j++){
  18.             cout<<a[i][j];
  19.         }
  20.         cout<<endl;
  21.     }
  22.  
  23.     cout<<endl;
  24.  
  25.     for(i = 1; i <= n; i++){
  26.         for(j = 1; j <= m; j++){
  27.             if(a[i][j] % 2 == 0){
  28.                 s = s + a[i][j];
  29.             }
  30.         }
  31.     }
  32.  
  33.     cout<<"Suma numerelor pare este: "<<s;
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment