
Помогите написать программу в паскале. За ранее спасибо. Задача на одномерный массив.Задание 3.
Даны два массива A и B, состоящих из одинакового числа элементов. Найти среднее арифметическое элементов каждогомассива и сравнить эти значения. Заполнение массива выберите по своему усмотрению.

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

uses crt;
var
a,b:array [1..100] of integer;
i,k:integer;
Sa,Sb:real;
begin
write('Введите количество элементов массивов: '); read(k);
clrscr;
randomize;
writeln('Массив А:');
for i:=1 to k do
begin
a[i]:=random(50)-25;
b[i]:=random(100)-50;
Sa:=Sa+b[i];
Sb:=Sb+a[i];
write (a[i]:4);
end;
writeln; writeln('Массив В:');
for i:=1 to k do
write (b[i]:4);
writeln;
Sa:=Sa/k; Sb:=Sb/k;
writeln ('Сумма элементов массива А: ',Sa);
writeln ('Сумма элементов массива В: ',Sb);
if Sa>Sb then writeln ('Ср.(А)>Ср.(В)')
else
if Sa<Sb then writeln ('Ср.(А)<Ср.(В)')
else writeln ('Ср.(А)=Ср.(В)');
end.



var
a,b:array [1..10] of integer;
i:integer;
s1,s2:real;
begin
randomize;
for i:=1 to 10 do begin
a[i]:=random(12)-1;
s1:=s1+a[i];
b[i]:=random(9)+1;
s2:=s2+b[i];
write (a[i],' ');
end;
writeln;
for i:=1 to 10 do write (b[i],' ');
writeln;
s1:=s1/10;
s2:=s2/10;
writeln ('S1 = ',s1);
writeln ('S2 = ',s2);
if s1>s2 then writeln ('S1>S2') else
if s1<s2 then writeln ('S1<S2') else writeln ('S1=S2');
readln;
end.



Writing a Program in Pascal to Compare the Arithmetic Mean of Two Arrays
To solve the given problem in Pascal, we can write a program that takes two arrays, calculates their arithmetic means, and then compares the calculated values. Below is a sample Pascal program to achieve this:
```pascal program CompareArrays;
const N = 5; // Number of elements in the arrays
type TArray = array[1..N] of Integer; // Define the array type
var A, B: TArray; // Declare the arrays i: Integer; // Loop variable sumA, sumB: Integer; // Variables to store the sum of elements in the arrays meanA, meanB: Real; // Variables to store the arithmetic mean of the arrays
begin // Fill array A (you can choose any method to fill the array) A[1] := 3; A[2] := 7; A[3] := 5; A[4] := 2; A[5] := 9;
// Fill array B (you can choose any method to fill the array) B[1] := 6; B[2] := 4; B[3] := 8; B[4] := 1; B[5] := 10;
// Calculate the sum of elements in array A sumA := 0; for i := 1 to N do sumA := sumA + A[i];
// Calculate the sum of elements in array B sumB := 0; for i := 1 to N do sumB := sumB + B[i];
// Calculate the arithmetic mean of array A meanA := sumA / N;
// Calculate the arithmetic mean of array B meanB := sumB / N;
// Compare the arithmetic means if meanA > meanB then writeln('The arithmetic mean of array A is greater than the arithmetic mean of array B') else if meanA < meanB then writeln('The arithmetic mean of array A is less than the arithmetic mean of array B') else writeln('The arithmetic mean of array A is equal to the arithmetic mean of array B');
end. ```
In this program, we have defined two arrays A and B, each consisting of 5 elements. We then calculate the sum of elements in each array and subsequently find their arithmetic means. Finally, we compare the arithmetic means of the two arrays and display the result.
Note: The actual method of filling the arrays can be chosen as per your preference. The provided program is a basic example to demonstrate the calculation and comparison of arithmetic means for two arrays.


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







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili