Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "math.h"
  3. #include "malloc.h"
  4. #include "float.h"
  5. #include "windows.h"
  6.  
  7.  
  8. void form_matrix(float **, int, int, float, float);
  9. void print_matrix(float **, int, int);
  10. float find_biggest(float **, int, int);
  11. void print_vector(float *, int);
  12.  
  13. int main() {
  14.     float *X;
  15.     float *Y;
  16.     float *Z;
  17.     float biggest_X, biggest_Y, biggest_Z;
  18.     float * vect = new float[3];
  19.  
  20.     form_matrix(&X, 3, 4, 5.7, 9.3);
  21.     printf("Matrix X:\n");
  22.     print_matrix(&X, 3, 4);
  23.  
  24.     form_matrix(&Y, 5, 5, 12.1, -3.8);
  25.     printf("\nMatrix Y:\n");
  26.     print_matrix(&Y, 5, 5);
  27.  
  28.     form_matrix(&Z, 6, 4, 10.5, 23.4);
  29.     printf("\nMatrix Z:\n");
  30.     print_matrix(&Z, 6, 4);
  31.  
  32.  
  33.     biggest_X = find_biggest(&X, 3, 4);
  34.     printf("\nBiggest Element in X: %4.1f\n", biggest_X);
  35.     biggest_Y = find_biggest(&Y, 5, 5);
  36.     printf("Biggest Element in Y: %4.1f\n", biggest_Y);
  37.     biggest_Z = find_biggest(&Z, 6, 4);
  38.     printf("Biggest Element in Z: %4.1f\n", biggest_Z);
  39.  
  40.     vect[0] = biggest_X;
  41.     vect[1] = biggest_Y;
  42.     vect[2] = biggest_Z;
  43.    
  44.     printf("\nVector:\n");
  45.     print_vector(vect, 3); //print_matrix(&vect, 3, 1);
  46.  
  47.     printf("\n\n");
  48.     system("pause");
  49.     return 0;
  50. }
  51.  
  52.  
  53. void form_matrix(float **Matrix, int rows, int cols, float a, float b) {
  54.     *Matrix = new float[rows*cols];
  55.  
  56.     for (int i = 0; i < rows; i++)
  57.         for (int j = 0; j < cols; j++)
  58.             *(*Matrix + i * cols + j) = a * (j + 1) * sinf((i + 1) / 2) + b * (i + 1) * cosf((j + 1) / 2);
  59. }
  60.  
  61. float find_biggest(float ** Matrix, int rows, int cols) {
  62.     float biggest = FLT_MAX;
  63.  
  64.     for (int i = 0; i < rows; i++)
  65.         for (int j = 0; j < cols; j++)
  66.             if (abs(*(*Matrix + i * cols + j) < biggest))
  67.                 biggest = fabs(*(*Matrix + i * cols + j));
  68.  
  69.     return biggest;
  70. }
  71.  
  72. void print_matrix(float ** Matrix, int rows, int cols) {
  73.     for (int i = 0; i < rows; i++) {
  74.         for (int j = 0; j < cols; j++)
  75.             printf("%7.1f ", *(*Matrix + i * cols + j));
  76.         printf("\n");
  77.     }
  78. }
  79.  
  80. void print_vector(float * arr, int len) {
  81.     for (int i = 0; i < len; i++)
  82.         printf("%7.1f ", arr[i]);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement