Trang chủ Tin Học Lớp 8 6. Hãy biến đổi ma trận bằng cách thay các...

6. Hãy biến đổi ma trận bằng cách thay các giá trị âm bằng trị tuyệt đối của ông Đếm số lượng số dương trong ma trận các số thực. Đếm số lượng các số nguyê

Câu hỏi :

giúp em vs ạ làm trên pascal. Em cảm ơn

image

Lời giải 1 :

6.

uses crt;
var n,m,i,j:integer;
a:array[1..100,1..100] of integer;

begin
clrscr;
readln(n,m);
for i:=1 to n do
for j:=1 to m do
 readln(a[i,j]);
for i:=1 to n do
for j:=1 to m do
 if a[i,j]<0 then a[i,j]:=abs(a[i,j]);
for i:=1 to n do
begin
for j:=1 to m do write(a[i,j],' ');
writeln;
end;
readln;
end.

7.

uses crt;
var n,m,i,j,d:integer;
a:array[1..100,1..100] of real;

begin
clrscr;
readln(n,m);
for i:=1 to n do
for j:=1 to m do
begin
 readln(a[i,j]);
 if a[i,j]>0 then d:=d+1;
end;
write(d);
readln;
end.

8.

uses crt;
var n,m,i,j,d:integer;
a:array[1..100,1..100] of integer;

function kt(n:integer):boolean;
var i:integer;
begin
if n<2 then exit(false)
else
 for i:=2 to round(sqrt(n)) do
  if n mod i=0 then exit(false);
 kt:=true;
end; 
begin
clrscr;
readln(n,m);
for i:=1 to n do
for j:=1 to m do
begin
 readln(a[i,j]);
 if kt(a[i,j]) then d:=d+1;
end;
write(d);
readln;
end.

9.

uses crt;
var n,m,i,j,d:integer;
x:real;
a:array[1..100,1..100] of real;

begin
clrscr;
readln(n,m,x);
for i:=1 to n do
for j:=1 to m do
begin
 readln(a[i,j]);
 if a[i,j]=x then d:=d+1;
end;
write(d);
readln;
end.

10.

uses crt;
var n,m,i,j,d:integer;
s,s2:string;
a:array[1..100,1..100] of integer;

begin
clrscr;
readln(n,m);
for i:=1 to n do
for j:=1 to m do
begin
 readln(a[i,j]);
 str(a[i,j],s);
 s2:=s2+s;

end;
write(length(s2));
readln;
end.

Thảo luận

Lời giải 2 :

uses crt;
var n,m,i,j,dd,dnt,csd,x,tsx: integer;
    s: string;
    a: array[1..10000,1..10000] of real;
function nt(n: integer): boolean;
begin
    nt:=true;
    if n<2 then nt:=false;
    for i:=2 to round(sqrt(n)) do if n mod 2 = 0 then begin
        nt:=false;
        break;
    end;
end;
begin
clrscr;
    dd:=0; csd:=0; dnt:=0; tsx:=0;
    readln(n,m);
    for i:=1 to n do for j:=1 to m do begin
        readln(a[i,j]);
        s:='';
        if a[i,j]>0 then begin
            dd:=dd+1;
            str(a[i,j],s);
            csd:=csd+length(s);
        end;
        if a[i,j]<0 then a[i,j]:=0-a[i,j];
        if nt(round(a[i,j])) and (round(a[i,j])=a[i,j]) then dnt:=dnt+1;
    end;
    readln(x);
    for i:=1 to n do for j:=1 to m do if a[i,j]=x then tsx:=tsx+1;
    // 6
    for i:=1 to n do begin
        for j:=1 to m do write(a[i,j]:0:2,' ');
        writeln;
    end;
    // 7
    writeln(dd);
    // 8
    writeln(dnt);
    // 9
    writeln(tsx);
    // 10
    write(csd);
    readln
end.

Bạn có biết?

Tin học, tiếng Anh: informatics, tiếng Pháp: informatique, là một ngành khoa học chuyên nghiên cứu quá trình tự động hóa việc tổ chức, lưu trữ, xử lý và truyền dẫn thông tin của một hệ thống máy tính cụ thể hoặc trừu tượng (ảo). Với cách hiểu hiện nay, tin học bao hàm tất cả các nghiên cứu và kỹ thuật có liên quan đến việc mô phỏng, biến đổi và tái tạo thông tin.

Nguồn : Wikipedia - Bách khoa toàn thư

Tâm sự 8

Lớp 8 - Năm thứ ba ở cấp trung học cơ sở, học tập bắt đầu nặng dần, sang năm lại là năm cuối cấp áp lực lớn dần nhưng các em vẫn phải chú ý sức khỏe nhé!

Nguồn : ADMIN :))

Liên hệ hợp tác hoặc quảng cáo: gmail

Điều khoản dịch vụ

Copyright © 2021 HOCTAPSGK