Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int gen_rand(int a, int b) {
- return rand() % (b + 1 - a) + a;
- }
- void gen_randarr(int size, int arr[], int a, int b) {
- for (int k = 0; k < size; k++) {
- int res = gen_rand(a, b);
- arr[k] = res;
- }
- }
- int calc_sum(int a, int b) {
- return a + b;
- }
- void question() {
- int res = calc_sum(4, 7); // res <-- 11
- int res2 = calc_sum(res, 12);
- cout << res << " " << res2 << endl;
- /*
- int a = 4, b = 7;
- int res = a + b;
- cout << res << endl;
- */
- }
- void test_memory() {
- int arr[]{ 1,2,3,4,5 };
- cout << arr[0] << endl;
- int val = 14;
- cout << arr << endl;
- cout << question << endl;
- cout << val << endl;
- cout << &val << endl;
- }
- void show_arr2d(int num_col, int num_row, int data[][3]) {
- for (int row = 0; row < num_row; row++) {
- for (int col = 0; col < num_col; col++) {
- cout << data[row][col] << " ";
- }
- cout << "\n";
- }
- }
- void test_array2d() {
- int matr[2][3]{
- {1,2,3},
- {4,5,6}
- };
- /*
- int matr[4][2][3]{
- {{1,2,3}, {4,5,6}},
- {{1,2,3}, {4,5,6}},
- {{1,2,3}, {4,5,6}},
- {{1,2,3}, {4,5,6}}
- };
- */
- cout << matr[0][1] << endl;
- show_arr2d(3, 2, matr);
- matr[1][0] = 9;
- for (int row = 0; row < 2; row++) {
- for (int col = 0; col < 3; col++) {
- cout << matr[row][col] << " ";
- }
- cout << "\n";
- }
- }
- void show_arr(int size, int arr[]) {
- for (int k = 0; k < size; k++) {
- cout << arr[k] << " ";
- }
- cout << endl;
- }
- void join_arr() {
- const int n = 5;
- int a[n]{ 1,2,3,4,5 };
- int b[n]{ 5,4,3,2,1 };
- int c[2 * n];
- for (int k = 0; k < n; k++) {
- /*
- c[k] = a[k];
- c[k+n] = b[k];
- */
- c[2*k] = a[k];
- c[2*k + 1] = b[k];
- }
- show_arr(2 * n, c);
- }
- void rotate_arr() {
- const int n = 5;
- int arr[n]{1,2,3,4,5};
- show_arr(n, arr);
- int tmp = arr[0];
- for (int k = 1; k < n; k++) {
- arr[k - 1] = arr[k];
- }
- arr[n - 1] = tmp;
- show_arr(n, arr);
- }
- int main() {
- cout << "Hello" << endl;
- //join_arr();
- rotate_arr();
- //test_array2d();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment