kxcoze

cringe_satie

Apr 9th, 2020
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. #include <iostream>        
  2. #include <iomanip>                                                  
  3. #include <clocale>          
  4.        
  5. using namespace std;            
  6.    
  7. const int n = 6, m = n + 1;    
  8.    
  9. void printArray(double *x) {                                                  
  10.     for (int i = 0; i < n; i++) {                                                  
  11.         cout << setprecision(2) << x[i] << ' ';                                                  
  12.     }                                                  
  13.     cout << '\n';                                                  
  14. }                                                                                  
  15.                                                                                    
  16. void printMatrix(double x[][m]) {                                                      
  17.     for (int i = 0; i < n; i++) {                                                            
  18.         for (int j = 0; j < m; j++) {                                                  
  19.             cout << setprecision(2) << setw(6) << x[i][j];                                    
  20.         }                                                              
  21.         cout << '\n';                                      
  22.     }                                                                  
  23. }                                                      
  24.                                                                
  25. int main() {                                                                  
  26.     srand(time(NULL));                                                              
  27.     setlocale(LC_ALL, "rus");                                                                
  28.     double a[n], mat[n][m];                                                    
  29.     for (int i = 0; i < n; i++) {                                                  
  30.         a[i] = (double) rand() / RAND_MAX * 21 - 10;                                          
  31.     }                                                                                        
  32.     printArray(a);                                                                  
  33.                                                                                        
  34.     for (int i = 0; i < n; i++) {                                          
  35.         for (int j = 0; j < m; j++) {                                              
  36.             if (j == 5)                                                                
  37.                 mat[i][j] = a[i];                                                            
  38.             else                                                                    
  39.                 mat[i][j] = (double) rand() / RAND_MAX * 21 - 10;                  
  40.         }                                                                                    
  41.     }                                                                                        
  42.     printMatrix(mat);                                                    
  43.     return 0;                                              
  44. }
Advertisement
Add Comment
Please, Sign In to add comment