Практика. Вказівники. Псевдодинамічні масиви

Для успішно даних завдань вам варто повторити такі теми як рандомні числа, цикли та та псевдодинамічні масиви.


Завдання 1: Програма рандомно обирає число в межах включно. Після чого створює масив цілих чисел довжини І заповнює цей масив рандомними числами в межах Після чого програма рахує суму чисел ліворуч та праворуч від центру і виводить з якої сторони сума буде більшою.


Приклад виконання програми:

        
            Sum left: 46
            Sum right: 29
            sum left > sum right
        
    

Приклад програми:


Завдання 2: В класі навчається учнів. Де вказує користувач. Всі учні зважуються і мають вагу в межах включно. Вага кожного учня визначається рандомно. Після чого, користувач може обрати один з наступних пунктів:

1) Вивести список учнів у порядку зростання ваги.

2) Вивести список учнів у порядку спадання ваги.

3) Вивести, яка вага є найбільшою.

4) Вивести, яка вага є найменшою.

5) Закрити програму.

Після того як користувач обирає необхідну дію, то програма знову демонструє меню вибору. Так триває до тієї пори поки користувач не виберу пункт (закрити програму). При цьому, при введені числа не зі списку меню програма повторює питання (повторно виводить меню вибору).


Приклад виконання програми:

        
            Enter the number of students: 17

            Choice menu:
            1) Display the list of students in order of increasing weight.
            2) Display the list of students in descending order of weight.
            3) Output which weight is the largest.
            4) Output which weight is the smallest.
            5) Close the program.
            Your choice: 1
            List of students in order of increasing weight:
            52.6 53 54.7 55.7 55.7 57.5 57.5 57.6 59.5 63.8 65.6 67.2 68.9 70.3 71.3 72.9 73

            Choice menu:
            1) Display the list of students in order of increasing weight.
            2) Display the list of students in descending order of weight.
            3) Output which weight is the largest.
            4) Output which weight is the smallest.
            5) Close the program.
            Your choice: 4
            The smallest weight: 52.6

            Choice menu:
            1) Display the list of students in order of increasing weight.
            2) Display the list of students in descending order of weight.
            3) Output which weight is the largest.
            4) Output which weight is the smallest.
            5) Close the program.
            Your choice: 3
            Greatest weight: 73

            Choice menu:
            1) Display the list of students in order of increasing weight.
            2) Display the list of students in descending order of weight.
            3) Output which weight is the largest.
            4) Output which weight is the smallest.
            5) Close the program.
            Your choice: 2
            List of students in descending order of weight:
            73 72.9 71.3 70.3 68.9 67.2 65.6 63.8 59.5 57.6 57.5 57.5 55.7 55.7 54.7 53 52.6

            Choice menu:
            1) Display the list of students in order of increasing weight.
            2) Display the list of students in descending order of weight.
            3) Output which weight is the largest.
            4) Output which weight is the smallest.
            5) Close the program.
            Your choice: 7
            Invalid choice. Try again.

            Choice menu:
            1) Display the list of students in order of increasing weight.
            2) Display the list of students in descending order of weight.
            3) Output which weight is the largest.
            4) Output which weight is the smallest.
            5) Close the program.
            Your choice: 5
            Goodbye!
        
    

Приклад програми:





Ви повинні увійти, щоб залишати коментарі.


Коментарі: