1.1-rasm. Saralash algoritmi uchun blok sxema.
Dastur kodi.
#include using namespace std; int main()
{int *arr; int size;
cout << "n = "; cin >> size;
if (size <= 0) {
cerr << "Massiv hajmi 0 dan katta bo’lishi kerak." << endl; return 1;}
arr = new int[size];
for (int i = 0; i < size; i++) { cout << "arr[" << i << "] = "; cin >> arr[i];
}
int max = arr[0];
for (int i = 1; i < size; i++) { if (arr[i] > max) {
max = arr[i];
}
}
cout << "max = " << max << endl; delete [] arr;
return 0;
}
Xulosa
Men amaliy mashg’ulot tayorlash davomida Masalaning yechimini topishning optimal usulini ishlab chiqishni usularini о‘rgandim. Massivning eng katta yoki eng kichik elementini topishning optimal usullarini aniqlash va bizga eng maqul yechimni toppish uchun kerek bo’lar ekan.
Do'stlaringiz bilan baham: |