Askja

Untitled

Jul 26th, 2022 (edited)
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <windows.h>
  4. #include <iomanip>
  5. #include <cstring>
  6. #include <conio.h>
  7.  
  8. /*
  9. - 1) Написать функцию которая выводит приветственное сообщение в консоль
  10. - 2) Сделать возможность ввода имени перед вводом всех чисел, а после вывода результатов расчёта, попрощаться с пользователем, то есть вывести: Имя, пока, друг
  11. - 3) Создать матрицу размером nxm, найти максимальный элемент в каждой строке и вывести на экран
  12. - 4) Создать два вектора, и прибавить к первому вектору второй вектор
  13. - 5) Написать функцию которая считает сумму трёх чисел и возвращает результат
  14. */
  15.  
  16. int MATRIX_SIZE = 4;
  17.  
  18. using namespace std;
  19.  
  20. // void <- ничего не возвращает
  21. float searchMax(float a, float b) {
  22.     if (a > b) {
  23.         return a;
  24.     }
  25.  
  26.     return b;
  27. }
  28.  
  29. void checkMax(float a, float b) {
  30.     if (a > b) {
  31.         cout << "a > b";
  32.     } else {
  33.         cout << "b > a";
  34.     }
  35. }
  36.  
  37. void setRussian() {
  38.     setlocale(0, "");
  39.     SetConsoleCP(1251);
  40.     SetConsoleOutputCP(1251);
  41. }
  42.  
  43. int main() {
  44.     setRussian();
  45.  
  46.     float j = 9.3133, f = 7236.37627;
  47.  
  48.     searchMax(j, f);
  49.  
  50.     //
  51.  
  52.     /*
  53.     0 = Black       8 = Gray
  54.             1 = Blue        9 = Light Blue
  55.             2 = Green       A = Light Green
  56.             3 = Aqua        B = Light Aqua
  57.             4 = Red         C = Light Red
  58.             5 = Purple      D = Light Purple
  59.             6 = Yellow      E = Light Yellow
  60.             7 = White       F = Bright White
  61.     */
  62.  
  63.     /*
  64.     char row[80];
  65.  
  66.     cout << "Ваше имя: ";
  67.     cin.getline(row, 80);
  68.  
  69.     cout << "Вы ввели: " << row << endl;
  70.     */
  71.  
  72.     //cin.get();
  73.  
  74.     //getchar();
  75.  
  76.     /*
  77.     string row; // ''
  78.  
  79.     cout << "Ваше имя: ";
  80.     getline(cin, row);
  81.  
  82.     cout << "Вы ввели: " << row << endl;
  83.     */
  84.  
  85.     //0 1 2 3
  86.     //8 5 4 3
  87.     //8 3 2 1
  88.     //8 4 3 1
  89.  
  90.     int **matrix = new int*[MATRIX_SIZE];
  91.  
  92.     for (int k = 0; k < MATRIX_SIZE; k++) {
  93.         matrix[k] = new int[MATRIX_SIZE];
  94.     }
  95.  
  96.     for (int k = 0; k < MATRIX_SIZE; k++) {
  97.         for (int j = 0; j < MATRIX_SIZE; j++) {
  98.             //cout << "Элемент массива " << k << "-" << j << ": ";
  99.             //cin >> matrix[k][j];
  100.             matrix[k][j] = (k + j);
  101.         }
  102.     }
  103.  
  104.     for (int k = 0; k < MATRIX_SIZE; k++) {
  105.         int summary = 0;
  106.  
  107.         for (int j = 0; j < MATRIX_SIZE; j++) {
  108.             cout << setw(4) << matrix[k][j] << " ";
  109.  
  110.             summary += matrix[k][j];
  111.         }
  112.  
  113.         cout << setw(20) << "Сумма элементов = " << summary << endl;
  114.     }
  115.  
  116.     //0 1 2 3
  117.    
  118.     /*
  119.     int *myVector = new int[MATRIX_SIZE];
  120.    
  121.     for (int k = 0; k < MATRIX_SIZE; k++) {
  122.         myVector[k] = k;
  123.     }
  124.  
  125.     for (int k = 0; k < MATRIX_SIZE; k++) {
  126.         cout << myVector[k];
  127.     }
  128.     */
  129.    
  130.     //SetConsoleCP(1251);
  131.     //SetConsoleOutputCP(1251);
  132.  
  133.     //system("chcp 1251");
  134.  
  135.     //int a = 9, b = 7;
  136.     //double c = 9.538487387387;
  137.     //float d = .9; // 0.9
  138.  
  139.     //cout.precision(3);
  140.     //cout << "c = " << setprecision(3) << c << endl;
  141.     //cout << "c = " << c << endl;
  142.  
  143.     //cout.width(20);
  144.  
  145.     //cout << "Какой-то текст" << setw(5) << d << "|" << setw(10) << a << endl;
  146.  
  147.     //cout << "Какой-то текст" << d << "|" << a << "|" << endl;
  148.  
  149.     //cout.setf(ios);
  150.     //cout << "Какой-то текст" << setw(20) << d << "|" << a << "|" << endl;
  151.  
  152.     // cout << "Переменная a = " << a << "; А переменная b = " << b << endl;
  153.     //printf("Переменная a = %d\nА переменная b = %d", a, b); // %s - string, %d - digit %f - float %lf - long float %c - char
  154.  
  155.     //printf("Переменная a перед изменением = %5.3lf", c); // %общее.после запятой+тип
  156.  
  157.     //scanf("%d", &a);
  158.  
  159.     //printf("Переменная a после изменения = %d", a);
  160.  
  161.     return 0;
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment