Вопрос задан 31.07.2018 в 13:19. Предмет Информатика. Спрашивает Тухватуллин Тимур.

Составьте программу, которая считает числа счастливых билетов, у которых сумма первых трех чисел и

сумма последних трех чисел равна 13.(Счастливый билет-сумма первых трех чисел равна сумме трех последних). Помогите решить, пожалуйста. Pascal. Нужно решить через "Repit, until".
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Галиев Ранис.
Var
   S,S1,i:byte;
   A:longint;
Begin
Write('Введите номер билета: ');ReadLn(A);
S:=0;
S1:=0;
i:=1;
Repeat
S:=S+A mod 10;
A:=A div 10;
i:=i+1
Until i>3;
Repeat
S1:=S1+A mod 10;
A:=A div 10;
i:=i+1
Until i>6;
if S<>S1 then WriteLn('Билет не является счастливым')
else WriteLn('Счастливый билет!!!')
End.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program to Calculate Lucky Tickets in Pascal

Here's a program written in Pascal that calculates the number of lucky tickets, where the sum of the first three digits is equal to the sum of the last three digits, and the sum is equal to 13. The program uses a "repeat until" loop to iterate through all possible ticket numbers and counts the lucky tickets.

```pascal program LuckyTickets;

var ticketNumber, firstThreeDigits, lastThreeDigits, sum: integer; luckyTicketCount: integer;

begin luckyTicketCount := 0; ticketNumber := 0;

repeat ticketNumber := ticketNumber + 1;

// Extract the first three digits firstThreeDigits := ticketNumber div 1000;

// Extract the last three digits lastThreeDigits := ticketNumber mod 1000;

// Calculate the sum of the first three digits sum := (firstThreeDigits div 100) + ((firstThreeDigits div 10) mod 10) + (firstThreeDigits mod 10);

// Check if the sum of the first three digits is equal to the sum of the last three digits and equal to 13 if (sum = (lastThreeDigits div 100) + ((lastThreeDigits div 10) mod 10) + (lastThreeDigits mod 10)) and (sum = 13) then luckyTicketCount := luckyTicketCount + 1;

until ticketNumber = 999999;

writeln('The number of lucky tickets is: ', luckyTicketCount); end. ```

This program initializes a variable `luckyTicketCount` to keep track of the number of lucky tickets found. It then uses a `repeat until` loop to iterate through all possible ticket numbers from 000000 to 999999.

Inside the loop, the program extracts the first three digits and the last three digits of the current ticket number using integer division and modulo operations. It then calculates the sum of the first three digits and checks if it is equal to the sum of the last three digits and equal to 13. If the conditions are met, the `luckyTicketCount` is incremented by 1.

Finally, the program outputs the total number of lucky tickets found.

Please note that this program assumes the ticket numbers are represented as integers and range from 000000 to 999999. If the ticket numbers have a different representation or range, the program may need to be modified accordingly.

I hope this helps! Let me know if you have any further questions.

0 0

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

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

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