Viết chương trình:
a. Nhập vào mảng A là dãy số nguyên
b. In ra hình dãy số A đó
c. In ra màn hình các số nguyên dương trong dãy số A
d. Tính tổng các số lẽ trong dãy lập trình pascal ta có câu lệnh
viết chương trình nhập vào một dãy số nguyên . số phân tử của dãy được nhập từ bàn phím a, in ra dãy số vừa nhập ra màn hình b, tính tổng các phân tử dương có trong dãy số
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i]>0 then t:=t+a[i];
writeln(t);
readln;
end.
Sử dụng biến mảng viết chương trình nhập vào một dãy số gồm N số nguyên tử bàn phím in ra màn hình tổng các số dương trong dãy số đó.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i]>0 then t:=t+a[i];
writeln(t);
readln;
end.
sử dụng biến mảng viết chương trình nhập vào 1 dãy số gồm n số nguyên từ bàn phím . In ra màn hình tổng các số dương trong dãy số đó
Var a:array[1..1000] of integer;
s:longint;
i,n:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i);readln(a[i]);
If a[i] > 0 then s:=s+a[i];
End;
Write('Tong la ',s);
Readln
End.
Câu 1 Viết chương trình:
a.Nhập vào mảng A là dãy số nguyên
b.In ra màn hình dãy số A đó
c.In ra màn hình các số nguyên dương trong dãy số A
d.Tính tổng các số lẻ trong dãy số A và hiện kết quả ra màn hình
Var a:array[1..200] of integer;
i,n,s,s1:integer;
begin
write('Nhap so luong phan tu n = ');readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,' = ');readln(a[i]);
end;
writeln('Cac so vua nhap la ');
for i:=1 to n do
write(a[i],' ');
for i:=1 to n do
if a[i] > 0 then s:=s+a[i];
for i:=1 to n do
if a[i] mod 2 = 1 then s1:=s1+a[i];
writeln('Tong cac so nguyen duong trong day la ',s);
write('Tong cac so le la ',s1);
readln;
end.
sử dụng biến mảng Viết chương trình nhập vào dãy số gồm n số nguyên từ bàn phím in ra màn hình tổng các số dương trong dãy số đó Giúp mình với
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i]>0 then t:=t+a[i];
writeln(t);
readln;
end.
Viết chương trình Nhập dãy số nguyên từ bàn phím. In ra màn hình các số lẻ có trong dãy được nhận. Tính tổng các số có trong dãy và in ra màn hình
Python:
n = input("Nhập dãy số nguyên: ").split()
n = [int(i) for i in n]
so_le = [i for i in n if i % 2 != 0]
tong = sum(n)
print("Các số lẻ trong dãy là: ", so_le)
print("Tổng các số trong dãy là: ", tong)
Pascal:
program tongvasole;
const
MAX_SIZE = 1000;
var
numbers: array[1..MAX_SIZE] of Integer;
count, i: Integer;
total: Integer;
begin
Write('Nhập số lượng phần tử trong dãy: ');
ReadLn(count);
for i := 1 to count do
begin
Write('Nhập phần tử thứ ', i, ': ');
ReadLn(numbers[i]);
end;
Write('Các số lẻ trong dãy là: ');
total := 0;
for i := 1 to count do
begin
if numbers[i] mod 2 <> 0 then
Write(numbers[i], ' ');
total := total + numbers[i];
end;
WriteLn;
WriteLn('Tổng các số trong dãy là: ', total);
end.
viết chương trình nhặp vào mảng B gồm N số nguyên hãy thực hiện lệnh in ra màn hình : a) các phần tử trông mảng B vừa nhập b) tổng các số chẵn không âm trông dãy c) in ra các số âm nếu có d) in ra tích các số dương
Bài 1 : Viết chương trình Pascal nhập vào 10 số thực bất kì , in ra màn hình tổng bình phương của các số âm
Bài 2 : Viết chườn trình nhập vào số n số tự nhiên đầu tiên , tính tổng các số chẵn có trong dãy số in kết quả ra màn hình
Bài 3 : Viết chưng trình nhập vào một mảng các số nguyên bất kì , in ra màn hình các số là số dương mà là số lẻ
Giúp mk với mn ơi , mk đang cần gấp Cảm ơn mn nhiều
Bài 1:program sothuc;
uses crt;
var a:array[1..10] of real;s,i,j:real;
begin
s:=0;
for i:=1 to 10 do begin writeln('A[',i,']=');readln(a[i]); end;
for i:=1 to 10 do if a[i]<0 then
for j:=1 to 10 do
begin a[j]:=sqr(a[i]); s:=s+a[j]; end;
writeln('tong binh phuong cac so am la: ',s:2:2); readln;
end. (Khi nào mình kiểm tra chạy lại trên phần mềm rồi sửa lại nếu sai nhé)
Bài 2:
program soduong;
uses crt;
var a:array[1..100] of integer;s,i,n:integer;
begin
clrscr;
writeln('nhap do dai cua day');readln(n);
for i:=1 to n do begin
writeln('a[',i,']=');readln(a[i]);
if a[i] mod 2 = 0 then s:=s+a[i] end;
writeln('tong so duong trong day la',s:2:0);readln
end.
Bài 3: các số dương mà là số lẻ là sao thế bạn????
a, Viết chương trình pascal nhập vào một dãy số nguyên n từ bàn phím b, in dãy vừa nhập ra màn hình. c, đếm xem bao nhiêu số dương. d, in kết quả số dương ra màn hình.
Program HOC24;
var a: array[1..32000] of integer;
i,n,d: integer;
begin
write('Nhap N: ');
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Day vua nhap la: ');
for i:=1 to n do write(a[i],' '); writeln;
d:=0;
for i:=1 to n do if a[i]>0 then d:=d+1;
write('Co ',d,' so duong');
readln
end.