створіть проект у якому можна обчислити суму ,або різницю ,або добуток або частку від ділення двох довільних дійсних чисел залежно від вибраного пункту розкривного списку Lazarus
Var f,s:text; st,sp:string; i:integer; c:char; begin assign(s,'text1.txt'); reset(s); while not Eof(s) do begin; readln(s,sp); st:=st+sp+chr(10)+chr(13); end; close(s); for i:=1 to length(st) div 2 do begin c:=st[i]; st[i]:=st[length(st)-i+1]; st[length(st)-i+1]:=c; end; assign(f,'text.txt'); rewrite(f); write(f,st); close(f); end.
Текст в файле text1.txt:
Simple text 1And another simple text 2New text
Текст в файле text.txt: txet weN2 txet elpmis rehtona dnA1 txet elpmiS
Как ч понял сортировка по неубыванию это сортировка по возрастанию. То есть легкие элементы всплывают наверх, а тяжелые перемещаются вниз:
//Pascal const m = 1000 var arr: array[1..m] of integer; n,i, j, k: integer; begin readln(n); write ('Исходный массив: '); for i := 1 to n do begin readln(arr[i]); end; //сортировка методом пузырька for i := 1 to n-1 do for j := 1 to n-i do if arr[j] > arr[j+1] then begin k := arr[j]; arr[j] := arr[j+1]; arr[j+1] := k end;
write ('Отсортированный массив: '); for i := 1 to n do write (arr[i]:4); end.
Алгоритм сортировки на классическом языке программирования С
# define SWAP(A,B) {A=A^B;B=A^B;A=A^B;} void bubblesort(int A[], int n) { int i, j; for(i = n-1 ; i > 0 ; i--) { for(j = 0 ; j < i ; j++) { if( A[j] > A[j+1] ) SWAP(A[j],A[j+1]); } } }
Var
f,s:text;
st,sp:string;
i:integer;
c:char;
begin
assign(s,'text1.txt');
reset(s);
while not Eof(s) do
begin;
readln(s,sp);
st:=st+sp+chr(10)+chr(13);
end;
close(s);
for i:=1 to length(st) div 2 do
begin
c:=st[i];
st[i]:=st[length(st)-i+1];
st[length(st)-i+1]:=c;
end;
assign(f,'text.txt');
rewrite(f);
write(f,st);
close(f);
end.
Текст в файле text1.txt:
Simple text
1And another simple text
2New text
Текст в файле text.txt:
txet weN2
txet elpmis rehtona dnA1
txet elpmiS
//Pascal
const m = 1000
var
arr: array[1..m] of integer;
n,i, j, k: integer;
begin
readln(n);
write ('Исходный массив: ');
for i := 1 to n do begin
readln(arr[i]);
end;
//сортировка методом пузырька
for i := 1 to n-1 do
for j := 1 to n-i do
if arr[j] > arr[j+1] then begin
k := arr[j];
arr[j] := arr[j+1];
arr[j+1] := k
end;
write ('Отсортированный массив: ');
for i := 1 to n do
write (arr[i]:4);
end.
Алгоритм сортировки на классическом языке программирования С
# define SWAP(A,B) {A=A^B;B=A^B;A=A^B;}
void bubblesort(int A[], int n)
{
int i, j;
for(i = n-1 ; i > 0 ; i--)
{ for(j = 0 ; j < i ; j++)
{
if( A[j] > A[j+1] ) SWAP(A[j],A[j+1]);
}
}
}