👤

Se citesc nr pana la intalnirea lui 0. Afisati cele mai mici 2 valori din cele citite.

Răspuns :

#include <bits/stdc++.h>
using namespace std;
int n, x, i, min1, min2;
int main()
{
cin >> x;
if(x == 0) {cout << 0 << " " << 0; return 0;}
min1 = min2 = x;
while(x != 0)
{
cin >> x;
if(x != 0 && x < min1) min2 = min1, min1 = x;
 else if(x != 0 && x < min2) min2 = x;
}
cout << min1 << " " << min2;
return 0;
}