Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "math.h"
- #include "malloc.h"
- #include "float.h"
- #include "windows.h"
- void form_matrix(float **, int, int, float, float);
- void print_matrix(float **, int, int);
- float find_biggest(float **, int, int);
- void print_vector(float *, int);
- int main() {
- float *X;
- float *Y;
- float *Z;
- float biggest_X, biggest_Y, biggest_Z;
- float * vect = new float[3];
- form_matrix(&X, 3, 4, 5.7, 9.3);
- printf("Matrix X:\n");
- print_matrix(&X, 3, 4);
- form_matrix(&Y, 5, 5, 12.1, -3.8);
- printf("\nMatrix Y:\n");
- print_matrix(&Y, 5, 5);
- form_matrix(&Z, 6, 4, 10.5, 23.4);
- printf("\nMatrix Z:\n");
- print_matrix(&Z, 6, 4);
- biggest_X = find_biggest(&X, 3, 4);
- printf("\nBiggest Element in X: %4.1f\n", biggest_X);
- biggest_Y = find_biggest(&Y, 5, 5);
- printf("Biggest Element in Y: %4.1f\n", biggest_Y);
- biggest_Z = find_biggest(&Z, 6, 4);
- printf("Biggest Element in Z: %4.1f\n", biggest_Z);
- vect[0] = biggest_X;
- vect[1] = biggest_Y;
- vect[2] = biggest_Z;
- printf("\nVector:\n");
- print_vector(vect, 3); //print_matrix(&vect, 3, 1);
- printf("\n\n");
- system("pause");
- return 0;
- }
- void form_matrix(float **Matrix, int rows, int cols, float a, float b) {
- *Matrix = new float[rows*cols];
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < cols; j++)
- *(*Matrix + i * cols + j) = a * (j + 1) * sinf((i + 1) / 2) + b * (i + 1) * cosf((j + 1) / 2);
- }
- float find_biggest(float ** Matrix, int rows, int cols) {
- float biggest = FLT_MAX;
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < cols; j++)
- if (abs(*(*Matrix + i * cols + j) < biggest))
- biggest = fabs(*(*Matrix + i * cols + j));
- return biggest;
- }
- void print_matrix(float ** Matrix, int rows, int cols) {
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++)
- printf("%7.1f ", *(*Matrix + i * cols + j));
- printf("\n");
- }
- }
- void print_vector(float * arr, int len) {
- for (int i = 0; i < len; i++)
- printf("%7.1f ", arr[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement