Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int maxn=20;
  6.  
  7. int elemszam(){
  8. int n=-1;
  9. while (n<1|| n>maxn) {
  10. cout << "Adj meg egy 1-nel nagyobb es " << maxn << "-nel/-nal kisebb szamot: " << endl;
  11. cin >> n;
  12. }
  13. return n;
  14. }
  15.  
  16. void beolvas(int x[], int n){
  17. for (int i=0; i<n; i++){
  18. cout << "Kerem adja meg a tomb " << i+1 << " elemet: " << endl;
  19. cin >> x[i];
  20. }
  21. }
  22.  
  23. bool nulla(int x[], int n){
  24. int i=0;
  25. while (i<n && x[i]!=0) i++;
  26. return i<n;
  27. }
  28.  
  29. float atlag(int x[], int n){
  30. int osszeg=0;
  31. for (int i=0; i<n; i++) osszeg=osszeg+x[i];
  32. return (float)osszeg/n;
  33. }
  34.  
  35. int main()
  36. {
  37. int n=elemszam();
  38. int x[n];
  39. beolvas(x,n);
  40. if (nulla(x,n)) cout << "Van 0." << endl;
  41. else cout << "Nincs 0." << endl;
  42. cout << "A tomb ertekeinek atlaga: " << atlag(x,n) << endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement