Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- void unforget() {
- std::cout << "Hello world" << std::endl;
- unsigned int val1 = 12;
- short val2 = 3434;
- long val3 = 314443;
- double pi_val = 3.14;
- float pi_rrr = -12.345;
- char ch = 'f';
- int arr[5]{ 1,2,3,4,5 };
- for (int k = 0; k < 5; ++k) {
- arr[k] = 5 - k;
- }
- int n = 0;
- while (n < 5) {
- ++n;
- arr[n] = (n < 3) ? 1 : 2;
- }
- do {
- --n;
- if ((n > 0) && (n < 3))
- arr[n] = 0;
- else
- arr[n] -= 2;
- } while (n >= 0);
- enum Mode { Sleep, Work };
- Mode mode = Sleep;
- switch (mode)
- {
- case Sleep:
- std::cout << "Sleep";
- break;
- case Work:
- std::cout << "Work";
- break;
- default:
- std::cout << "Unknown mode";
- break;
- }
- setlocale(LC_ALL, "Russian");
- std::cin >> val1;
- }
- void reference() {
- int a = 5;
- cout << &a << " " << a << endl;
- int veryLongAndnonComfortabeleName = 15;
- int &val = veryLongAndnonComfortabeleName;
- val++;
- cout << veryLongAndnonComfortabeleName
- << " " << val << endl;
- cout << &veryLongAndnonComfortabeleName
- << " " << &val << endl;
- veryLongAndnonComfortabeleName = -123;
- cout << veryLongAndnonComfortabeleName
- << " " << val << endl;
- cout << &veryLongAndnonComfortabeleName
- << " " << &val << endl;
- }
- void pointers() {
- int val = 12;
- int * pval = &val;
- cout << pval << " " << &val << endl;
- cout << *pval << " " << val << endl;
- char ch = 'g';
- char* pch = &ch;
- cout << std::hex << (int)(pch) << " " << (int)(&ch) << endl;
- cout << *pch << " " << ch << endl;
- }
- void pointers_vs_array() {
- double arr[5]{ 0.1, 0.2, 0.3, 0.4, 0.5 };
- cout << *arr << " "
- << *(&(arr[0])) << " "
- << arr[0] << endl << endl;
- // arr[k] ~ *(arr + k)
- double* pa = &(arr[0]);
- double* pb = &(arr[4]);
- cout << pa - pb << endl;
- cout << arr << " "
- << arr + 1 << " "
- << arr[0] << " "
- << *(arr + 1) << endl;
- cout << endl;
- for (int k = 0; k < 5; ++k) {
- cout << *(arr + k) << " ";
- }
- cout << endl;
- for (double* pk = arr; pk <= &(arr[4]); pk++) {
- cout << *pk << " ";
- }
- cout << endl;
- }
- void maxVal() {
- int a = 5;
- int b = 10;
- // дальше a и b - не используем
- int* pa = &a;
- int* pb = &b;
- cout << ((*pa > *pb) ? (*pa) : (*pb));
- cout << endl;
- }
- void getSign() {
- int val = 0;
- int *pval = &val;
- cout << "Enter number: ";
- cin >> *pval;
- if (*pval > 0) {
- cout << "positive";
- } else if (*pval < 0) {
- cout << "negative";
- } else {
- cout << "zero";
- }
- cout << endl;
- }
- void my_swap1() {
- int a = 5;
- int b = 7;
- //ваш код
- int tmp = a;
- a = b;
- b = tmp;
- cout << a << " " << b << endl;
- //надо: 7 5
- }
- void my_swap2() {
- int a = 5;
- int b = 7;
- //ваш код
- a = a + b;
- b = a - b;
- a = a - b;
- cout << a << " " << b << endl;
- //надо: 7 5
- }
- void logicBits() {
- int a = 5; // 101
- int b = 6; // 110
- cout << a << " | " << b << " = "
- << (a | b) << endl;
- cout << a << " & " << b << " = "
- << (a & b) << endl;
- cout << a << " ^ " << b << " = "
- << (a ^ b) << endl;
- }
- void shift() {
- int x = 1;
- int y = 2;
- const int Ny = 4;
- const int Nx = 3;
- while (x < 0)
- x += Nx;
- while (y < 0)
- y += Ny;
- int arr[Ny][Nx]{ {1, 2, 3},
- {4, 5, 6},
- {7, 8, 9},
- {4, 6, 8} };
- for (int ky = 0; ky < Ny; ky++) {
- for (int kx = 0; kx < Nx; kx++)
- cout << arr[ky][kx] << " ";
- cout << endl;
- }
- int arr2[Ny][Nx];
- for (int ky = 0; ky < Ny; ky++)
- for (int kx = 0; kx < Nx; kx++)
- // тут правильная строчка кода
- for (int ky = 0; ky < Ny; ky++) {
- for (int kx = 0; kx < Nx; kx++)
- cout << arr2[ky][kx] << " ";
- cout << endl;
- }
- /*
- * in:
- * 1 2 3
- * 4 5 6
- * 7 8 9
- * 4 6 8
- *
- * out:
- * 8 9 7
- * 6 8 4
- * 2 3 1
- * 5 6 4
- */
- }
- void main() {
- shift();
- }
Advertisement
Add Comment
Please, Sign In to add comment