Mavzu: Standart turlari


Download 26.11 Kb.
Sana16.11.2023
Hajmi26.11 Kb.
#1778170
Bog'liq
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 newtonBinom(int a, int b, int n) {
vector result;

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 coefficients = newtonBinom(a, b, n);


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