Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. const int MAX_tab = 100;
  12. int a, b, x, max=0, min=0, counter=0;
  13. int tab[MAX_tab];
  14. float srednia=0;
  15. srand(time(NULL));
  16.  
  17.  
  18.  
  19. cout << "Y=(x^2-a)(x-b) \n" << "Podaj wartosci a i b \n";
  20. cout << "a: ";
  21. cin >> a;
  22. cout << "b: ";
  23. cin >> b;
  24.  
  25. for (int i=0; i < MAX_tab; i++)
  26. {
  27. x = rand() % 101 - 50;
  28. tab[i] = (x*x - a)*(x - b);
  29.  
  30. if (tab[i] == tab[0])
  31. {
  32. max = tab[0];
  33. min = tab[0];
  34. }
  35.  
  36. if (max < tab[i])
  37. {
  38. max = tab[i];
  39. }
  40.  
  41. if (min > tab[i])
  42. {
  43. min = tab[i];
  44. }
  45.  
  46. srednia = srednia + tab[i];
  47. counter++;
  48. }
  49.  
  50.  
  51. cout <<"\n"<< "Najwieksza wartosc w tabeli to " << max << " a najmniejsza to " << min;
  52. cout <<"\n"<< "Srednia wszystkich wynikow to " << srednia / counter;
  53. cout << "\n";
  54. cout << "\n";
  55.  
  56. for (int i = 0; i < MAX_tab; i++)
  57. {
  58. cout << setw(10) << tab[i];
  59. }
  60.  
  61.  
  62. cout << "\n";
  63. system("PAUSE");
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement