Guest User

Untitled

a guest
Mar 2nd, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <ctime>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7. int const N = 1000;
  8. int t[N];
  9. int n, a, b;
  10. double wynik;
  11.  
  12. void pytanie()
  13. {
  14. cout << "Podaj liczbe elementow ciagu: ";
  15. cin >> n;
  16. cout << "Jakim sposobem chcesz wybrac liczby?" << endl;
  17. cout << "Moj zakres: (1)" << endl;
  18. cout << "Wylosowane z zakresu: (2)" << endl;
  19.  
  20. }
  21.  
  22. void dane()
  23. {
  24. int wybor;
  25. cin >> wybor;
  26. switch (wybor) {
  27.  
  28. case 1:
  29. cout << "Podaj zakres elementow ciagu [a,b]: ";
  30. cin >> a >> b;
  31.  
  32. srand(unsigned(time(0)));
  33. for (int i = 0; i < n; i++) {
  34. t[i] = a + rand() % (b - a + 1);
  35. }
  36. for (int i = 0; i < n; i++) {
  37. cout << t[i] << " ";
  38. }
  39. break;
  40.  
  41. case 2:
  42. cout << "Podaj " << n << " " << "liczb:";
  43. for (int i = 0; i < n; i++) {
  44. cin >> t[i];
  45. }
  46. break;
  47. }
  48. }
  49. void sprawdzenie()
  50. {
  51. wynik = 0;
  52. for (int i = 1; i < n; i++) // wyraz jest rosnacy jeśli bi < bi+1 => bi - bi+1<0 {
  53. wynik += t[i - 1];
  54. if (t[i] > wynik) { //sprawdzenie czy bi+1-bi>0
  55. cout << "\nCiag b jest rosnacy ";
  56. }
  57. else {
  58. cout << "\nCiag b jest malejacy";
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. pytanie();
  65. dane();
  66. sprawdzenie();
  67.  
  68. system("PAUSE");
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment