const nx = 20; var x: array[1..nx, 1..nx] of integer;z:array[1..nx*2] of integer; i, j, k,n,r,t: integer; begin Writeln('Введите размер матрицы n');Read(n); for i := 1 to n do begin for j := 1 to n do begin Read(k);x[i, j] := k; end;end; Writeln('Исходный массив'); for i := 1 to n do begin for j := 1 to n do begin Write(x[i, j]:4); if x[i, j]>0 then begin t:=t+1; z[t]:=x[i, j];end; end; Writeln; end; Writeln;Writeln('Одномерный массив'); for j := 1 to t do Write(z[j]:4); end.
На языке C++ будет так:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a,b,c;
double D, x1, x2;
cout<<"Введите a"<<endl;
cin >>a;
cout<<"Введите b"<<endl;
cin >>b;
cout<<"Введите c"<<endl;
cin >>c;
if (a == 0){
cout<<"Коэффициент a не может быть равен 0"<<endl;
return 0;
}
D = b*b - 4 * a * c;
if (D >= 0){
if (D == 0){
x1 = -(double)b /(2*a);
cout<<"x = "<<x1<<endl;
}
else{
x1 = (-b + sqrt(D)) / (2*a);
x2 = (-b - sqrt(D)) / (2*a);
cout<<"x1 = "<<x1<<endl;
cout<<"x2 = "<<x2<<endl;
}
}
else{
cout<<"Корней нет. D = "<<D<<endl;
}
return 0;
}
var x: array[1..nx, 1..nx] of integer;z:array[1..nx*2] of integer;
i, j, k,n,r,t: integer;
begin
Writeln('Введите размер матрицы n');Read(n);
for i := 1 to n do begin
for j := 1 to n do begin
Read(k);x[i, j] := k; end;end;
Writeln('Исходный массив');
for i := 1 to n do begin
for j := 1 to n do begin
Write(x[i, j]:4);
if x[i, j]>0 then begin t:=t+1; z[t]:=x[i, j];end;
end;
Writeln; end;
Writeln;Writeln('Одномерный массив');
for j := 1 to t do
Write(z[j]:4);
end.