Array:
0.284 0.284 0.284 0.284 0.284 0.284 0.284 0.284 0.284 0.284
0.754 0.754 0.754 0.754 0.754 0.754 0.754 0.754 0.754 0.754
-0.911 -0.911 -0.911 -0.911 -0.911 -0.911 -0.911 -0.911 -0.911 -0.911
0.004 0.004 0.004 0.004 0.004 0.004 0.004 0.004 0.004 0.004
0.907 0.907 0.907 0.907 0.907 0.907 0.907 0.907 0.907 0.907
-0.76 -0.76 -0.76 -0.76 -0.76 -0.76 -0.76 -0.76 -0.76 -0.76
-0.275 -0.275 -0.275 -0.275 -0.275 -0.275 -0.275 -0.275 -0.275 -0.275
0.989 0.989 0.989 0.989 0.989 0.989 0.989 0.989 0.989 0.989
-0.548 -0.548 -0.548 -0.548 -0.548 -0.548 -0.548 -0.548 -0.548 -0.548
-0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533
Array:
0 0 0 0 0 0 0 0 0 0
0.754 0 0 0 0 0 0 0 0 0
-0.911 -0.911 0 0 0 0 0 0 0 0
0.004 0.004 0.004 0 0 0 0 0 0 0
0.907 0.907 0.907 0.907 0 0 0 0 0 0
-0.76 -0.76 -0.76 -0.76 -0.76 0 0 0 0 0
-0.275 -0.275 -0.275 -0.275 -0.275 -0.275 0 0 0 0
0.989 0.989 0.989 0.989 0.989 0.989 0.989 0 0 0
-0.548 -0.548 -0.548 -0.548 -0.548 -0.548 -0.548 -0.548 0 0
-0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533 -0.533 0
Для продолжения нажмите любую клавишу . . .
Построить вещественную матрицу A(10,10)
Построить вещественную матрицу A(10,10) по правилу: aij = cos (i2 + 5). Заменить нулями все ее элементы, расположенные на главной диагонали и выше нее. Вывести на печать для сравнения обе матрицы.
Может кто чем нибудь хотя бы помочь в решении, а то я вообще не представляю как сделать это.
Код:
#include <iostream>
using std::cout;
using std::endl;
using std::system;
double** createRandomArray(int size);
void deleteRandomArray(int size, double** Array);
void outRandomArray(int size, double** Array);
void modifyRandomArray(int size, double** Array);
int main()
{
int size = 10;
double** Array = createRandomArray(size);
outRandomArray(size, Array);
modifyRandomArray(size, Array);
cout << endl;
outRandomArray(size, Array);
deleteRandomArray(size, Array);
cout << endl;
system("pause");
return 0;
}
double** createRandomArray(int size)
{
double** Array = new double*[size];
for (int idx = 0; idx < size; idx++)
{
Array[idx] = new double[size];
}
for (int idx = 0; idx < size; idx++)
{
for (int jdx = 0; jdx < size; jdx++)
{
Array[idx][jdx] = round((cos(idx * 2 + 5)*1000))/1000.0;
}
}
return Array;
}
void deleteRandomArray(int size, double** Array)
{
for (int idx = 0; idx < size; idx++)
delete[] Array[idx];
delete[] Array;
}
void outRandomArray(int size, double** Array)
{
cout << "Array:" << endl;
for (int idx = 0; idx < size; idx++)
{
for (int jdx = 0; jdx < size; jdx++)
{
cout << Array[idx][jdx] << "\t";
}
cout << endl;
}
}
void modifyRandomArray(int size, double** Array)
{
for (int idx = 0; idx < size; idx++)
{
Array[idx][idx] = 0;
for (int jdx = idx + 1; jdx < size; jdx++)
{
Array[idx][jdx] = 0;
}
}
}
using std::cout;
using std::endl;
using std::system;
double** createRandomArray(int size);
void deleteRandomArray(int size, double** Array);
void outRandomArray(int size, double** Array);
void modifyRandomArray(int size, double** Array);
int main()
{
int size = 10;
double** Array = createRandomArray(size);
outRandomArray(size, Array);
modifyRandomArray(size, Array);
cout << endl;
outRandomArray(size, Array);
deleteRandomArray(size, Array);
cout << endl;
system("pause");
return 0;
}
double** createRandomArray(int size)
{
double** Array = new double*[size];
for (int idx = 0; idx < size; idx++)
{
Array[idx] = new double[size];
}
for (int idx = 0; idx < size; idx++)
{
for (int jdx = 0; jdx < size; jdx++)
{
Array[idx][jdx] = round((cos(idx * 2 + 5)*1000))/1000.0;
}
}
return Array;
}
void deleteRandomArray(int size, double** Array)
{
for (int idx = 0; idx < size; idx++)
delete[] Array[idx];
delete[] Array;
}
void outRandomArray(int size, double** Array)
{
cout << "Array:" << endl;
for (int idx = 0; idx < size; idx++)
{
for (int jdx = 0; jdx < size; jdx++)
{
cout << Array[idx][jdx] << "\t";
}
cout << endl;
}
}
void modifyRandomArray(int size, double** Array)
{
for (int idx = 0; idx < size; idx++)
{
Array[idx][idx] = 0;
for (int jdx = idx + 1; jdx < size; jdx++)
{
Array[idx][jdx] = 0;
}
}
}
Результат
Код:
Код:
Module Module1
Sub Main()
Dim size = 8
Dim mArray(size, size) As Double
For idx = 0 To size
For jdx = 0 To size
mArray(idx, jdx) = Math.Round((Math.Cos(idx * 2 + 5) * 1000)) / 1000.0
Next jdx
Next idx
out(size, mArray)
modify(size, mArray)
Console.WriteLine()
out(size, mArray)
Console.ReadLine()
End Sub
Sub out(ByVal size, ByRef mArray)
Console.WriteLine("Array:")
For idx = 0 To size
For jdx = 0 To size
Console.Write(mArray(idx, jdx))
Console.Write(vbTab)
Next jdx
Console.WriteLine()
Next idx
End Sub
Sub modify(ByVal size, ByRef mArray)
For idx = 0 To size
mArray(idx, idx) = 0
For jdx = idx + 1 To size
mArray(idx, jdx) = 0
Next jdx
Next idx
End Sub
End Module
Sub Main()
Dim size = 8
Dim mArray(size, size) As Double
For idx = 0 To size
For jdx = 0 To size
mArray(idx, jdx) = Math.Round((Math.Cos(idx * 2 + 5) * 1000)) / 1000.0
Next jdx
Next idx
out(size, mArray)
modify(size, mArray)
Console.WriteLine()
out(size, mArray)
Console.ReadLine()
End Sub
Sub out(ByVal size, ByRef mArray)
Console.WriteLine("Array:")
For idx = 0 To size
For jdx = 0 To size
Console.Write(mArray(idx, jdx))
Console.Write(vbTab)
Next jdx
Console.WriteLine()
Next idx
End Sub
Sub modify(ByVal size, ByRef mArray)
For idx = 0 To size
mArray(idx, idx) = 0
For jdx = idx + 1 To size
mArray(idx, jdx) = 0
Next jdx
Next idx
End Sub
End Module