ToniDev

Medie artimetica nr. divizibile cu 7

Dec 2nd, 2021 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, a, contor = 0; //n = cate numere vrei sa testam
  7.     // contor = cate numere sunt divizibile cu 7
  8.    
  9.     int medie_aritmetica, suma = 0;
  10.  
  11.     cout << "Introdu n: "; cin >> n;
  12.  
  13.     for (int i = 0; i < n; i++) // repetam de n ori
  14.     {
  15.         cout << "Introdu a: "; cin >> a;
  16.  
  17.         if (a % 7 == 0) //verificam daca nr. introdus este divizibil cu 7
  18.         {
  19.             suma += a;
  20.             contor++; // contor = contor + 1
  21.         }
  22.     }
  23.  
  24.     medie_aritmetica = suma / contor; //formula matematica pt media aritmetica
  25.  
  26.     cout << "Media: " << medie_aritmetica << endl;
  27.  
  28.     return 0;
  29. }
Add Comment
Please, Sign In to add comment