Program SumAndMul;
Uses Crt;
var a:array[1..10] of real;
i:integer;
sum,mul:longint;
begin
clrscr;
for i:=1 to 10 do
write('Введите -', i,' число:' );
readln(a[i]);
end;
sum:=0;mul:=1;
if (a[i]>0) then sum:=sum+a[i];
if (a[i]<0 ) then mul:=mul*a[i];
writeln('Сумма положительных элементов: ',sum);
writeln('Произведение отрицательных элементов: ',mul);
readkey;
end.
Объяснение:
Сначала заполним массив, затем выведем его содержимое.
---
Sub Main()
Dim a as Double = 1
Dim b as Double = 15
Dim h as Double = 0.92
Dim n as Integer = int((b - a) / h)
Dim Z() As Double = New Double(n) {}
Dim i as Double
For i = 0 To n
Z(i) = Math.Cos(a + h * i) + Math.Tan(a + h * i)
Next
Console.WriteLine("Z(" & i+1 & ") = " & Z(i))
End Sub
Результат работы этой программы:
Z(1) = 2.09771003052304
Z(2) = -3.0884493200958
Z(3) = -1.26594678050156
Z(4) = -0.103295451547362
Z(5) = 30.831517973736
Z(6) = -0.0383774051794511
Z(7) = 1.21343345934296
Z(8) = 2.67822720165008
Z(9) = -2.28928714730523
Z(10) = -1.13533602598861
Z(11) = 0.265586431867902
Z(12) = -7.87130103019394
Z(13) = 0.283584171679959
Z(14) = 1.3388270225723
Z(15) = 4.05676371484264
Z(16) = -1.89632897888172
Program SumAndMul;
Uses Crt;
var a:array[1..10] of real;
i:integer;
sum,mul:longint;
begin
clrscr;
for i:=1 to 10 do
begin
write('Введите -', i,' число:' );
readln(a[i]);
end;
sum:=0;mul:=1;
for i:=1 to 10 do
begin
if (a[i]>0) then sum:=sum+a[i];
if (a[i]<0 ) then mul:=mul*a[i];
end;
writeln('Сумма положительных элементов: ',sum);
writeln('Произведение отрицательных элементов: ',mul);
readkey;
end.
Объяснение:
Сначала заполним массив, затем выведем его содержимое.
---
Sub Main()
Dim a as Double = 1
Dim b as Double = 15
Dim h as Double = 0.92
Dim n as Integer = int((b - a) / h)
Dim Z() As Double = New Double(n) {}
Dim i as Double
For i = 0 To n
Z(i) = Math.Cos(a + h * i) + Math.Tan(a + h * i)
Next
For i = 0 To n
Console.WriteLine("Z(" & i+1 & ") = " & Z(i))
Next
End Sub
---
Результат работы этой программы:
Z(1) = 2.09771003052304
Z(2) = -3.0884493200958
Z(3) = -1.26594678050156
Z(4) = -0.103295451547362
Z(5) = 30.831517973736
Z(6) = -0.0383774051794511
Z(7) = 1.21343345934296
Z(8) = 2.67822720165008
Z(9) = -2.28928714730523
Z(10) = -1.13533602598861
Z(11) = 0.265586431867902
Z(12) = -7.87130103019394
Z(13) = 0.283584171679959
Z(14) = 1.3388270225723
Z(15) = 4.05676371484264
Z(16) = -1.89632897888172