{zadanie 1a}
usus
SysUntils;
var a,b,nawias,suma,:real;i:integer;
begin
writeln('wprowadz 1 liczbe');
readln(a);
if a<>0 then
begin
nawias:=a*a;
suma:=a;
i:=2;
randomize;
writeln('podaj ',i,' liczbe');
readln(a);
nawias:=nawias+a*a;
i:=i+1
until a=0;
b:=sin(nawias)*sin(nawias);
suma:=suma+b;
writeln('suma jest rowna',suma)
end else writeln('wprowadziles 0 suma jest 0');
readln;
end.
{tutaj bylo mowione ze potega
e wszyskie elementy maj byc do kwadratu}
{zadanie 1b}
usus
SysUntils;
var a,b,c,potega,suma,:real;i:integer;
begin
writeln('podaj 1 liczbe');
readln(a);
if a=0 then writeln(wprowadziles 0 suma rowna 0') else
begin
writeln('wprowadz 2 liczbe');
readln(b);
if b=0 then writeln('sumajest rowna',a/2*exp(a*a)) else
begin
i:=3;
suma:=a*b/2;
potega:=a*a+b*b;
randomize;
writeln('wprowadz',i,'liczbe');
readln(c);
potega:=potega+c*c;
i:=i+1
until c=0
end;
end;
suma:=suma+exp(potega);
writeln('suma jest rowna',suma);
readln;
end.
{zadanie 2a}
usus
SysUntils;
type a = array[1..40] of integer
var b:a;n,i:integer;suma,nawias:real
begin
randomize;
writeln('wprowadz ilość elementów');
readln(n)
until (n>=1) and (n<=40);
For i:=1 to n do begin
writeln('podaj',i,'element');
readln(b);
end;
nawias:=0;
suma:=b[1]*b[1];
For i:=2 to (n-1) do nawias:=nawias+b[i]*b[i]*b[i];
suma:=suma+1/2*nawias+b[n]*b[n];
writeln('suma jest rowna ',suma);
readln;
end.
{zadanie 2b}
usus
SysUntils;
type a = array[1..40] of integer
var b:a;n,i:integer;suma,licznik,mianownik:real
begin
randomize;
writeln('wprowadz ilość elementów');
readln(n)
until (n>=1) and (n<=40);
For i:=1 to n do begin
writeln('podaj',i,'element');
readln(b);
end;
licznik:=1;
mianownik:=0;
For i:=1 to n do licznik:=licznik*b[i];
For i:=1 to n do mianownik:=mianownik + i*b[i]*b[i];
suma:=3*licznik/(1+mianownik);
writeln('suma jest rowna',suma);
readln;
end.
{zadanie 3}
usus
SysUntils;
type a = array[1..40] of integer
var b:a;n,k,i:integer;suma,liczba:real
begin
randomize;
writeln('wprowadz ilość elementów');
readln(n)
until (n>=1) and (n<=40);
randomize;
writeln('wprowadz liczbe k');
readln(k)
until (k>=1) and (n<=3);
For i:=1 to n do begin
writeln('podaj',i,'element');
readln(b);
end;
if k=1 then begin
liczba:=0;
For i:=1 to n do liczba:=liczba+b[i]*b[i];
writeln('suma jest rowna',1/n*liczba-b[n]) end
else begin
if k=2 then begin
liczba:=0;
For i:=1 to n do liczba:=liczba + a[i]/i;
writeln('suma jest rowna ', b[n]*liczba) end
else begin
liczba:=1;
For i:=1 to n do liczba:=liczba*a[i];
writeln('suma jest rowna ', 1/b[n]* arctg(liczba)) end
end;
end.
{tego pewny nie jestem}
Lepiej sprawdź swoje programy
w kompilatorze bo widać trochę błędów
w nich (randomize jest do losowania
a Tobie chodziło o repeat) .
Ja zamieszczam swoją wersje programu 1[a]:
uses
SysUtils;
var
i:integer;
a_1,a,nawias,s_1: real;
begin
writeln('Podaj 1 wyraz ciagu');
readln(a_1);
if a_1<>0 then
begin
i:=2;
nawias:=a_1*a_1;
writeln('Podaj ',i,' element ciagu');
readln(a);
while a<>0 do
begin
nawias:=nawias+a*a;
writeln('Podaj ',i,' element ciagu');
readln(a);
i:=i+1;
end;
end
else
writeln('element nie moze byc rowny 0');
s_1:=a_1+sin(nawias)*sin(nawias);
writeln('S1= ',s_1:0:2);
readln;
end.
Program 1[b]:
uses
SysUtils;
var
i:integer;
a_1,a_2,a,potega,s_2: real;
begin
writeln('Podaj 1 wyraz ciagu');
readln(a_1);
if (a_1<>0) then
begin
writeln('Podaj 2 wyraz ciagu');
readln(a_2);
if (a_2<>0) then
begin
i:=3;
potega:=a_1*a_1+a_2*a_2;
writeln('Podaj ',i,' element ciagu');
readln(a);
i:=4;
while a<>0 do
begin
potega:=potega+a*a;
writeln('Podaj ',i,' element ciagu');
readln(a);
i:=i+1;
end;
end
else
writeln('element nie moze byc rowny 0');
end
else
writeln('element nie moze byc rowny 0');
s_2:=((a_1+a_2)/2)*exp(potega);
writeln('S2= ',s_2:0:2);
readln;
end.
uses
SysUtils;
var
a,n,i,i_a:integer;
suma,srednia: real;
begin
writeln('Podaj ilosc liczb');
readln(n);
i:=1;
i_a:=0;
suma:=0;
while n>=i do
begin
writeln('Podaj ',i,' liczbe');
readln(a);
if (a MOD 2=0) and (a>0) then
begin
suma:=suma+a;
i_a:=i_a+1;
end;
if i_a>0 then
begin
srednia:=suma/i_a;
writeln('srednia= ',srednia:0:2);
end
else
writeln('Nie ma takich liczb');
readln;
end.
uses
SysUtils;
var
n,i:integer;
el_max,el: real;
begin
writeln('Podaj ilosc liczb');
readln(n);
i:=1;
el_max:=0;
begin
while n>=i do
begin
writeln('Podaj ',i,' element');
readln(el);
if (el>el_max) and (el<=30) then
el_max:=el;
i:=i+1;
end;
writeln('el_max:= ',el_max:0:2);
readln;
end.
Wyprowadzić ciąg liczb.
Utworzyć 2 nowe ciągi:
-w jednym dodatnie
-w drugim ujemne
-wyprowadzic
uses
SysUtils;
type a=array[1..40] of integer;
var b,c,d:a;i,ilosc1,ilosc2,n:integer;
begin
repeat;
writeln('podaj liczbe elementow');
readln(n);
until (n>=1) and (n<=40);
For i:=1 to n do begin
writeln('podaj ',i,' element');
readln(b[i]) end;
ilosc1:=0;
For i:=1 to n do begin
if b[i]>0 then begin
ilosc1:=ilosc1+1;
c[ilosc1]:=b[i] end;
if b[i]<0 then begin
ilosc2:=ilosc2+1;
d[ilosc2]:=b[i] end end;
Writeln('ilosc liczb dodatni - ',ilosc1,' ilosc liczb ujemnych - ',ilosc2);
For i:=1 to ilosc1 do writeln('liczby dodatnie to: ',c[i]);
For i:=1 to ilosc2 do writeln('liczby ujemne to: ',d[i]);
readln;
end.
Masz dwa ciągi y1,y2...y10 i x1,x2...x10 których wartości pobierasz, nie pobierasz ilości elementów, bo z góry jest narzucona i ma być 10.
- wybrać max z x,
-suma x>0,
-zastąpić y<0 na max,
wyświetlić sumę, max i wszystkie elementy y.
Jakoś tak to było, dokładnie nie pamiętam, ale coś w tym stylu.
uses
SysUtils;
(((deklarujemy zmienne)))
var
x:array[1..10]of real;
y:array[1..10]of real;
suma,max:real;
i:byte;
begin
(((wczytanie danych)))
for i:=1 to 10 do
begin
writeln('Podaj wartość x');
readln(x[i]);
writeln('Podaj wartość y');
readln(y[i]);
end;
(((wybór max z x)))
max:=x[1];
for i:=1 to 10 do
if x{i]>max then
max:=x[i];
(((obliczamy sumę x>0)))
suma:=0;
for i:=1 to 10 do
if x[i]>0 then
suma:=suma+x[i];
(((zastępujemy y<0 na max)))
for i:=1 to 10 do
if y[i]<0 then
y[i]:=max;
(((Wyświetlamy)))
writeln('Maksymalna wartość x to: ',max:5:2);
writeln('Suma x>0 wynosi: ',suma:5:2);
(((Wyświetlamy cały ciąg y (w pionowym słupku,
co by ładnie wyglądało i używamy zamiast write to writeln))))
for i:=1 to 10 do
writeln('y ',i,' = ',y[i]:5:2);
end.
uses
SysUtils;
var i,a,max_a,suma:integer;
begin
writeln('Podaj 1 liczbe');
readln(a);
max_a:=a;
suma:=a;
for i:=2 to 10 do
begin
writeln('Podaj ',i,' liczbe');
readln(a);
suma:=suma+a;
if max_a<a then
max_a:=a;
end;
writeln('Max element: ',max_a,' a suma: ',suma);
readln;
end.