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
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
#include <stdio.h>
#include <windows.h>
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int const n=3;
int mas[n][n];
int sum1, sum2;
bool magik;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
{
printf("mas[%d][%d] = ", i+1, j+1);
scanf("%d",&mas[ i ][ j ]);
}
printf("\nВведенная матрица:\n");
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
printf("%d ",mas[ i ][ j ]);
}
printf("\n");
}
sum1=0;
sum2=0;
for (int i = 0; i<n; i++)
{
sum1 += mas[ i ][ i ];
sum2 += mas[ i ][ n-1-i ];
}
printf("Сумма главной диагонали = %d\n", sum1);
printf("Сумма побочной диагонали = %d\n", sum2);
magik = true;
for (int i=0; i<n; i++)
{
if (sum1==sum2)
{
sum2=0;
for (int j=0; j<n; j++)
{
sum2 += mas[ i ][ j ];
}
} else { magik=false; break; }
}
if (magik==true)
{
for (int i=0; i<n; i++)
{
if (sum1==sum2)
{
sum2=0;
for (int j=0; j<n; j++)
{
sum2 += mas[ j ][ i ];
}
}
else { magik=false; break; }
}
}
if (magik==true)
printf("\nМатрица является магическим квадратом\n");
else
printf("\nМатрица не является магическим квадратом\n");
system("pause");
return 0;
}