Programy w Pascalu
1. funkcja wielowarunkowa (z mechanizmem powtarzania całości programu)
program funkcja;
uses crt;
var x,y: longint;
odp:char;
begin
odp:='n';
repeat
clrscr;
writeln('podaj x'); readln(x);
if x>=8 then y:=x*x-1 else
if x<(-2) then y:=x else y:=-2;
write('f(x)=',y);
readln;
writeln('Czy chcesz zakonczyc prace?? (t/n) ');
readln(odp);
until (odp='t') or (odp='T');
end.
2.Równania
a) równanie liniowe (0=ax+b)
program rownanielinowe;
var a,b,x:real;
begin
write ('podaj a=');
readln(a);
write ('podaj b=');
readln(b);
if ((a=0) and (b=0)) then writeln ('nieskonczenie wiele rozwiazan');
if ((a=0) and (b<>0)) then writeln ('brak rozwiazan')
else x:=-b/a;
writeln ('x=' , x:2:2);
readln;
end.
b) kwadratowe (0=ax^+bx+c)
program rownanie_kwadratowe;
uses crt;
Var a, b, c, x1, x2, d, x : Real;
begin
clrscr;
write('podaj a=');
readln(a);
write('podaj b=');
readln(b);
write('podaj c=');
readln(c);
if a=0 then
begin
Writeln('Rozwiazywanie funkcji liniowej');
if (b=0) and (c<>0) then
Writeln('Brak rozwiazań');
if (b<>0) and (c<>0) then
begin
x:=(-c)/b;
Writeln('Rozwiaenie x=',x:2:2);
end;
if (b=0) and (c=0) then writeln('Równanie nieoznaczone - nieskończenie wiele rozwiązań');
if (b<>0) and (c=0) then writeln('Rozwiazaniem rownania jest liczba 0');
readln;
end
else
begin
d:=(b*b)-4*a*c;
if d>0 then
begin
x1:=(-b-sqrt(d))/2*a;
x2:=(-b+sqrt(d))/2*a;
writeln('rozwiĄzania:');
writeln('x1=', x1:2:2);
writeln('x2=', x2:2:2);
end;
if d<0 then writeln('brak rozwiĄza');
if d=0 then
begin
x:=(-b)/2*a;
writeln('rozwiĄzanie=', x:2:2);
end;
readln;
end;
end.
c)układ równań liniowych
program ukad_rownan_liniowych;
uses crt;
var a1,b1,a2,b2,c1,c2,w,wx,wy,x,y:real;
begin
clrscr;
write('podaj a1 ');readln(a1);
write('podaj b1 ');readln(b1);
write('podaj c1 ');readln(c1);
write('podaj a2 ');readln(a2);
write('podaj b2 ');readln(b2);
write('podaj c2 ');readln(c2);
w:=a1*b2-a2*b1;
wx:=c1*b2-c2*b1;
wy:=a1*c2-c1*a2;
if w<>0 then
begin
x:=wx/w;
y:=wy/w;
writeln('x = ',x:4:2,', y = ',y:4:2);
end
else
begin
if (wx=0) and (wy=0) then writeln('Nieskonczenie wiele rozw.')
else writeln('Brak rozwiazan');
end;
readln;
end.