Вопрос задан 15.06.2023 в 15:26. Предмет Информатика. Спрашивает Кирьянова Виктория.

Зарисуйте блок-схемы циклов и Решите самостоятельно: Покупатель должен заплатить в кассу S руб. У

него есть купюры номиналом: 1,2,5,10,50,100,500. Сколько купюр разного номинала отдаст покупатель, если он начинает платить с самых крупных?
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Есьман Настёна.

Язык программирования Java:

Схема не совсем корректная. Лучше сделайте её самостоятельно.

  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.    public static void main(String[] args) {
  5.        Scanner scan = new Scanner(System.in);
  6.        System.out.print("Покупатель должен заплатить в кассу s руб., введите s:\ns = ");
  7.        int s = scan.nextInt();
  8.        s = sum(s, 500);
  9.        s = sum(s, 100);
  10.        s = sum(s, 50);
  11.        s = sum(s, 10);
  12.        s = sum(s, 5);
  13.        s = sum(s, 2);
  14.        s = sum(s, 1);
  15. }
  16.    public static int sum(int s, int num) {
  17.        int counter = 0;
  18.        while (s >= num) {
  19.            counter++;
  20.            s -= num;
  21.        }
  22.        System.out.println(num + " руб. - " + counter + " раз");
  23.        return s;
  24.    }
  25. }


0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Problem Analysis

To solve this problem, we need to determine the number of banknotes of different denominations that the buyer will give if they start paying with the largest banknotes and need to pay an amount of S rubles.

Solution

To solve this problem, we can use a simple algorithm to calculate the number of banknotes of each denomination that the buyer will give. We start by dividing the amount to be paid by the largest banknote denomination and then continue with the remainder until the amount becomes zero.

Let's calculate the number of banknotes of each denomination step by step.

1. 500 Rubles Banknotes: - Divide the amount by 500 and note the quotient and remainder. - Update the amount to the remainder for the next step.

2. 100 Rubles Banknotes: - Divide the updated amount by 100 and note the quotient and remainder. - Update the amount to the remainder for the next step.

3. 50 Rubles Banknotes: - Divide the updated amount by 50 and note the quotient and remainder. - Update the amount to the remainder for the next step.

4. 10 Rubles Banknotes: - Divide the updated amount by 10 and note the quotient and remainder. - Update the amount to the remainder for the next step.

5. 5 Rubles Banknotes: - Divide the updated amount by 5 and note the quotient and remainder. - Update the amount to the remainder for the next step.

6. 2 Rubles Banknotes: - Divide the updated amount by 2 and note the quotient and remainder. - Update the amount to the remainder for the next step.

7. 1 Ruble Banknotes: - The remaining amount will be the number of 1 Ruble banknotes.

Let's calculate the number of banknotes for each denomination using this algorithm.

Calculation

Let's assume the amount to be paid is S rubles. We'll calculate the number of banknotes for each denomination using the algorithm described above.

Conclusion

By following the algorithm, we can determine the number of banknotes of different denominations that the buyer will give if they start paying with the largest banknotes.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос