fork download
  1. #include <iostream>
  2.  
  3. int average(int* total, int* count);
  4.  
  5. int main()
  6. {
  7. int total[1];
  8. int temp[1];
  9. int count[1];
  10. *total = 0;
  11. *count = 0;
  12. std::cin >> *temp;
  13. while (*temp >= 0)
  14. {
  15. *total += *temp;
  16. ++(*count);
  17. std::cin >> *temp;
  18. }
  19. std::cout << average(total, count) << std::endl;
  20. return 0;
  21. }
  22.  
  23. int average(int* total, int* count)
  24. {
  25. if (*count != 0)
  26. {
  27. return (*total)/(*count);
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 2728KB
stdin
2
4
6
8
10
-1
stdout
6