Паскаль. 1. Буратино купил n учебников по a сольдо и m ручек по b карандашей по n сольдо. a, b, m, n задаются с клавиатуры. Рассчитать общую стоимость покупки. 2. Среди трёх введённых чисел вывести количество положительных. 3. Найти сумму всех чисел от a до b. 4. Сгенерировать массив. Подсчитать число положительных чисел.
var a, b, m, n, cost, positiveCount, i, sum: integer; arr: array1..101..101..10 of integer;
begin // Ввод данных write′EnterthenumberoftextbooksboughtbyBuratino:′'Enter the number of textbooks bought by Buratino: '′EnterthenumberoftextbooksboughtbyBuratino:′; readlnnnn; write′Enterthecostofeachtextbook:′'Enter the cost of each textbook: '′Enterthecostofeachtextbook:′; readlnaaa; write′EnterthenumberofpensboughtbyBuratino:′'Enter the number of pens bought by Buratino: '′EnterthenumberofpensboughtbyBuratino:′; readlnmmm; write′Enterthecostofeachpen:′'Enter the cost of each pen: '′Enterthecostofeachpen:′; readlnbbb;
// Вычисляем общую стоимость покупки cost := na + mb; writeln′Thetotalcostofthepurchaseis:′,cost'The total cost of the purchase is: ', cost′Thetotalcostofthepurchaseis:′,cost;
// Определяем количество положительных чисел среди трех введенных positiveCount := 0; write′Enterthreenumbers:′'Enter three numbers: '′Enterthreenumbers:′; for i := 1 to 3 do begin readlnarr[i]arr[i]arr[i]; if arriii > 0 then positiveCount := positiveCount + 1; end; writeln′Thenumberofpositivenumbersenteredis:′,positiveCount'The number of positive numbers entered is: ', positiveCount′Thenumberofpositivenumbersenteredis:′,positiveCount;
// Вычисляем сумму всех чисел от a до b sum := 0; write′Entertwonumbers(aandb):′'Enter two numbers (a and b): '′Entertwonumbers(aandb):′; readlnaaa; readlnbbb; for i := a to b do begin sum := sum + i; end; writeln′Thesumofallnumbersfrom′,a,′to′,b,′is:′,sum'The sum of all numbers from ', a, ' to ', b, ' is: ', sum′Thesumofallnumbersfrom′,a,′to′,b,′is:′,sum;
// Генерируем массив и считаем количество положительных чисел for i := 1 to 10 do begin arriii := random202020 - 10; if arriii > 0 then positiveCount := positiveCount + 1; end; writeln′Thenumberofpositivenumbersinthearrayis:′,positiveCount'The number of positive numbers in the array is: ', positiveCount′Thenumberofpositivenumbersinthearrayis:′,positiveCount;
program Lab3_Pascal;
uses crt;
var
a, b, m, n, cost, positiveCount, i, sum: integer;
arr: array1..101..101..10 of integer;
begin
// Ввод данных
write′EnterthenumberoftextbooksboughtbyBuratino:′'Enter the number of textbooks bought by Buratino: '′EnterthenumberoftextbooksboughtbyBuratino:′;
readlnnnn;
write′Enterthecostofeachtextbook:′'Enter the cost of each textbook: '′Enterthecostofeachtextbook:′;
readlnaaa;
write′EnterthenumberofpensboughtbyBuratino:′'Enter the number of pens bought by Buratino: '′EnterthenumberofpensboughtbyBuratino:′;
readlnmmm;
write′Enterthecostofeachpen:′'Enter the cost of each pen: '′Enterthecostofeachpen:′;
readlnbbb;
// Вычисляем общую стоимость покупки
cost := na + mb;
writeln′Thetotalcostofthepurchaseis:′,cost'The total cost of the purchase is: ', cost′Thetotalcostofthepurchaseis:′,cost;
// Определяем количество положительных чисел среди трех введенных
positiveCount := 0;
write′Enterthreenumbers:′'Enter three numbers: '′Enterthreenumbers:′;
for i := 1 to 3 do
begin
readlnarr[i]arr[i]arr[i];
if arriii > 0 then
positiveCount := positiveCount + 1;
end;
writeln′Thenumberofpositivenumbersenteredis:′,positiveCount'The number of positive numbers entered is: ', positiveCount′Thenumberofpositivenumbersenteredis:′,positiveCount;
// Вычисляем сумму всех чисел от a до b
sum := 0;
write′Entertwonumbers(aandb):′'Enter two numbers (a and b): '′Entertwonumbers(aandb):′;
readlnaaa;
readlnbbb;
for i := a to b do
begin
sum := sum + i;
end;
writeln′Thesumofallnumbersfrom′,a,′to′,b,′is:′,sum'The sum of all numbers from ', a, ' to ', b, ' is: ', sum′Thesumofallnumbersfrom′,a,′to′,b,′is:′,sum;
// Генерируем массив и считаем количество положительных чисел
for i := 1 to 10 do
begin
arriii := random202020 - 10;
if arriii > 0 then
positiveCount := positiveCount + 1;
end;
writeln′Thenumberofpositivenumbersinthearrayis:′,positiveCount'The number of positive numbers in the array is: ', positiveCount′Thenumberofpositivenumbersinthearrayis:′,positiveCount;
end.