Advertisement
dxvmxnd

Untitled

Sep 21st, 2023
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. int main() {
  6. setlocale(LC_ALL, "Rus");
  7. bool isNotCorrect = false;
  8. int n, i;
  9. int array[100];
  10. cout << "Введите колличество элементов в массиве\n";
  11. do {
  12. cin >> n;
  13. if (cin.fail()) {
  14. isNotCorrect = true;
  15. cout << "Данные введены неккоректно\n\n";
  16. cin.clear();
  17. while (cin.get() != '\n');
  18. }
  19. else {
  20. for (i = 1; i <= n; ++i) {
  21. do {
  22. cout << "Введите " << i << " элемент массива\n";
  23. cin >> array[i];
  24. if (cin.fail()) {
  25. isNotCorrect = true;
  26. cout << "Данные введены неккоректно\n\n";
  27. cin.clear();
  28. while (cin.get() != '\n');
  29. }
  30. else {
  31. isNotCorrect = false;
  32. }
  33. } while (isNotCorrect);
  34. }
  35. }
  36. } while (isNotCorrect);
  37. cout << "Вывод на экран: \n";
  38. for (i = 1; i <= n; ++i) {
  39. if (i % 2 == 1) {
  40. cout << array[i] << ", ";
  41. }
  42. else {
  43. cout << "-" << array[i] << ", ";
  44. }
  45. }
  46. return 0;
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement