Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, suma=0, min, max, sumd=0, sumu=0;
  7. cout << "Program wyznaczający sumę, średnią, minimalną, maksymalną oraz sume liczb dodatnich i ujemnych" << endl;
  8. cout << "Podaj liczbę cyfr do wprowadzenia: ";
  9. cin >> n;
  10. int tab[n];
  11. for(int i=0; i<n; i++) {
  12. // WCZYTANIE
  13. cout << "T[" << i << "] = ";
  14. cin >> tab[i];
  15. }
  16.  
  17. min = tab[0];
  18. max = tab[0];
  19. for(int i=0; i<n; i++) {
  20. // === SUMA ===
  21. suma += tab[i];
  22. // === SUMA ===
  23.  
  24. // === MIN ===
  25. if(tab[i] < min) min = tab[i];
  26. // === MIN ===
  27.  
  28. // === MAX ===
  29. if(tab[i] > max) max = tab[i];
  30. // === MAX ===
  31.  
  32. // === SUMA + ===
  33. if(tab[i] > 0) sumd += tab[i];
  34. // === SUMA + ===
  35.  
  36. // === SUMA - ===
  37. if(tab[i] < 0) sumu += tab[i];
  38. // === SUMA - ===
  39. }
  40. cout << "Suma wynosi: " << suma << endl;
  41.  
  42. cout << "Średnia wynosi: " << (double)suma/(double)n << endl;
  43.  
  44. cout << "Minimalna wynosi: " << min << endl;
  45.  
  46. cout << "Maksymalna wynosi: " << max << endl;
  47.  
  48. cout << "Suma dodatnich wynosi: " << sumd << endl;
  49.  
  50. cout << "Suma ujemnych wynosi: " << sumu << endl;
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement