Untitled
#include <iostream> using namespace std; int main() { const int size = 5; int numbers[size]; cout << "Podaj 5 liczb calkowitych: " << endl; for (int i = 0; i < size; ++i) { cin >> numbers[i]; } for (int i = 0; i < size; ++i) { cout << numbers[i] << ", "; } cout << "\n\n"; int smallest = numbers[0]; int result = numbers[0]; for (int i = 1; i < size; ++i) { if (numbers[i] < smallest) { smallest = numbers[i]; } } cout << "Najmniejszy element: " << smallest << endl; bool finder = false; for (int i = 0; i < size; ++i) { if (numbers[i] > smallest) { result = numbers[i]; finder = true; break; } } if (finder) { for (int i = 0; i < 5; ++i) { if (numbers[i] > smallest && numbers[i] < result) { result = numbers[i]; } } } if (!finder) { cout << "Nie ma drugiej najmniejszej liczby, wszyskie liczby podane sa takie same.!"; } else { cout << "Druga najmniejsza liczba to: " << result << endl; } return 0; }
Leave a Comment