Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #include <iostream>
  2. #include "fstream"
  3. #include "iomanip"
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char* argv[])
  8. {
  9. const int nmax = 20;
  10. float wektor[nmax];
  11. int a = 1, instr, pozmin, pozmax;
  12. while (1)
  13. {
  14. int n, i;
  15. float min, max;
  16. cout << "Podaj rozmiar wektora n(<=" << nmax << ")" << endl;
  17. cin >> n, i;
  18. if (n > 0 && n <= nmax)
  19. {
  20. for (i = 0; i < n;i++)
  21. {
  22. cout << "Podaj wektor [" << i + 1 << "]" << endl;
  23. cin >> wektor[i];
  24. }
  25. cout << "Wektor ma postac:" << endl;
  26. for (i = 0; i < n; i++)
  27. cout << setw(8) << setprecision(2) << fixed << wektor[i] << " ";
  28. cout << endl;
  29. cout << "Wybierz sposob obliczania:1 lub 2" << endl;
  30. cin >> instr;
  31. switch (instr)
  32. {
  33. case 1:
  34. min = wektor[0];
  35. for (i = 1;i < n;i++)
  36. if (wektor[i] < min)
  37. {
  38. min = wektor[i];
  39. max = wektor[0];
  40. pozmin = i + 1;
  41. }
  42. else
  43. {
  44. max = wektor[0];
  45. if (max < wektor[i])
  46. {
  47. max = wektor[i];
  48. pozmax = i + 1;
  49. }
  50. else
  51. {
  52. max;
  53. pozmax = i + 1;
  54. }
  55. }
  56. cout << "wartosc minimalna w wektorze wynosi:" << min << endl;
  57. cout << "Jest na pozycji:" << pozmin << endl;
  58. cout << "wartosc maksymalna w wektorze wynosi:" << max << endl;
  59. cout << "Jest na pozycji:" << pozmax << endl;
  60. break;
  61. case 2:
  62. int nrmin = 0;
  63. int nrmax;
  64. for (i = 1;i < n;i++)
  65. if (wektor[i] < wektor[nrmin])
  66. {
  67. nrmin = i;
  68. nrmax = 0;
  69. }
  70. else
  71. {
  72. nrmax = 0;
  73. if (wektor[nrmax] < wektor[i])
  74. {
  75. nrmax = i;
  76. }
  77. else
  78. nrmax;
  79. }
  80. cout << "wartosc minimalna w wektorze wynosi" << wektor[nrmin] << endl;
  81. cout << "wartosc maksymalna w wektorze wynosi:" << wektor[nrmax] << endl;
  82. break;
  83. }
  84. }
  85. else
  86. cout << "Zly rozmiar wektora" << endl;
  87. cout << "Aby ponownie uruchomic program podaj dowolna liczbe, zas aby wyjsc z programu podaj 0" << endl;
  88. cin >> a;
  89. if (a == 0)
  90. break;
  91. }
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement