Advertisement
Dambosin

Untitled

Mar 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5. struct tstk {
  6. int inf;
  7. tstk *a;
  8. }*a;
  9.  
  10. tstk *AddStask(tstk *sp, int inf) {
  11. tstk *spt = new tstk;
  12. spt->inf = inf;
  13. spt->a = sp;
  14. return spt;
  15. }
  16.  
  17. tstk *ReadStackD(tstk *sp, int &inf) {
  18. if (sp == NULL) return NULL;
  19. tstk *spt = sp;
  20. inf = sp->inf;
  21. sp = sp->a;
  22. delete spt;
  23. return sp;
  24. }
  25.  
  26. tstk *DelStackAll(tstk *sp) {
  27. tstk *spt; int inf;
  28. while (sp != NULL) {
  29. spt = sp;
  30. inf = sp->inf;
  31. cout << inf << " ";
  32. sp = sp->a;
  33. delete spt;
  34. }
  35. return NULL;
  36. }
  37. int main()
  38. {
  39. setlocale(LC_ALL, "Russian");
  40. srand(time(NULL));
  41. int n;
  42. cout << "Введите количество элементов ";
  43. cin >> n;
  44. int sum = 0;
  45. for (int i = 0; i < n; i++) {
  46. int temp = rand() % 101 - 50;
  47. cout << temp << " ";
  48. sum += temp;
  49. a = AddStask(a, temp);
  50. }
  51. double sr = double(sum) / n;
  52. cout << endl;
  53. cout << "Среднее значение " << sr<<endl;
  54. while (a != NULL) {
  55. int temp;
  56. a = ReadStackD(a, temp);
  57. if (temp > sr)cout << temp << " ";
  58. }
  59.  
  60. DelStackAll(a);
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement