Mavzu: Standart turlari
Download 26.11 Kb.
|
MTA 1-amaliyot
Mavzu: Standart turlari 3. k-darajagacha bo‘lgan Nyuton binomi sonlaridan vektor hosil qiling. Nyuton binomi sonlari quyidagicha aniqlanadi. 1 1 1 2 1 2 1 3 3 1 3 1 4 6 4 1 … 1 5 10 10 5 1 k #include #include using namespace std; int daraja(int x, int n) { int result = 1; for (int i = 0; i < n; ++i) { result *= x; } return result; } vector vector for (int k = 0; k <= n; ++k) { int coefficient = daraja(n, k); coefficient *= daraja(a, n - k); coefficient *= daraja(b, k); result.push_back(coefficient); } return result; } int main() { int a, b, n; cout << "a ni kiriting: "; cin >> a; cout << "b ni kiriting: "; cin >> b; cout << "n ni kiriting: "; cin >> n; vector cout << "(a + b)^" << n << " = "; for (int i = 0; i <= n; ++i) { cout << coefficients[i] << "x^" << (n - i) << " "; if (i < n) { cout << "+ "; } } return 0; } Download 26.11 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling