Николай Веселуха
Высший разум
(382979)
13 лет назад
// Аленка_2011-12-04-b
#include <iostream>
#include <ctime>
using namespace std;
#define N 3
int detMatrix(int *, const int, const int);
int main()
{
srand((unsigned) time(NULL));
int a[N][N], det;
for (int n = 0; n < N; n++, cout << endl)
for (int m = 0; m < N; m++)
{
a[n][m] = 9 - rand() % 19;
cout << '\t' << a[n][m];
}
cout << endl;
cout << " Matrix determinant = " << detMatrix(&a[0][0], N, N);
fflush(stdin);
cin.get();
return 0;
}
int detMatrix(int * a, const int n, const int m)
{
int * p;
p = a;
return *p * *(p + 4) * *(p + 8) + *(p + 1) * *(p + 5) * *(p + 6) + *(p + 2) * *(p + 3) * *(p + 7) - *(p + 2) * *(p + 4) * *(p + 6) - *(p + 1) * *(p + 3) * *(p + 8) - *(p + 5) * *(p + 7) * *p;
}
Николай ВеселухаВысший разум (382979)
13 лет назад
Окончательный вариант выглядит так:
#include <iostream>
#include <ctime>
using namespace std;
#define N 3
int detMatrix(int *);
int main()
{
srand((unsigned) time(NULL));
int a[N][N], det;
for (int n = 0; n < N; n++, cout << endl)
for (int m = 0; m < N; m++)
{
a[n][m] = 9 - rand() % 19;
cout << '\t' << a[n][m];
}
cout << endl;
cout << " Matrix determinant = " << detMatrix(&a[0][0]);
fflush(stdin);
cin.get();
return 0;
}
int detMatrix(int * p)
{
return *p * *(p + 4) * *(p + 8) + *(p + 1) * *(p + 5) * *(p + 6) + *(p + 2) * *(p + 3) * *(p + 7) - *(p + 2) * *(p + 4) * *(p + 6) - *(p + 1) * *(p + 3) * *(p + 8) - *(p + 5) * *(p + 7) * *p;
}
Шелдон Купер
Знаток
(413)
13 лет назад
Конец семестра на подходе, студенты лезут в интернет за халявой. Хотя бы потрудились формулы написать, какие требуются, или хотите чтоб за вас еще их поискали?
АленкаПрофи (716)
13 лет назад
Ну вообщето я не студентка! А с задачками прошу помоч чтобы помогли разобраться! Я это для себя делаю!
ra
Высший разум
(113320)
13 лет назад
#include <iostream>
#include <iomanip>
int main() {
int a[3][3];
int r, c, i = 0;
std::cout << "array:" << std::endl;
for (r = 0; r < 3; ++r) {
for (c = 0; c < 3; ++c) {
std::cout << std::setw(4) << (a[r][c] = ++i);
}
std::cout << std::endl;
}
std::cout << "result: "
<< (a[0][0] * a[1][1] * a[2][2] + a[0][1] * a[1][2] * a[2][0] +
a[0][2] * a[1][0] * a[2][1] - a[0][2] * a[1][1] * a[2][0] -
a[0][1] * a[1][0] * a[2][2] - a[0][0] * a[1][2] * a[2][1]) << std::endl;
return 0;
}