Viết chương trình thực hiện các công việc sau: a) Nhập vào một dãy gồm N số nguyên ( N > 50) b) Hãy in ra màn hình dãy số vừa nhập c) Nhập vào một số nguyên x bất kỳ. In ra các số chia hết cho x
bài 1:Viết chương trình nhập vào một mảng số nguyên gồm n phần tử(n<100) nhập từ bàn phím thực hiện các công việc sau:
a)In ra màn hình các phần tử của mảng vừa nhập.
b) Sắp xếp dãy số nguyên theo thứ tự tăng dần.
c) Nhập số nguyên x bất kì.Tính số chắn lớn nhất không được vượt quá x.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,kt,max,x,j,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Mang ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('Day tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
write('Nhap x='); readln(x);
max:=0;
kt:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]<=x) then
begin
if max<a[i] then max:=a[i];
kt:=1;
end;
if kt=0 then writeln('Trong day khong co so le')
else writeln('So chan lon nhat khong vuot qua ',x,' la: ',max);
readln;
end.
viết chương trình nhập vào 1 dãy số nguyên gồm n phần tử .Sau đó thực hiện các công việc sau:
in dãy số vừa nhập ra màn hình
tổng của dãy số vừa nhập
tổng các số chẵn trong dãy
tổng các số lẻ trong dãy
tổng các số chia hết cho 3
mỗi n đc nhập từ bàn phím
giúp mình với các cậu ơi
mình cảm ơn nhiều
uses crt;
var a: array[1..100] of integer;
i,n,s,s1,s2,s3: integer;
begin
clrscr;
writeln(' nhap so phan tu cua day'); readln(n);
for i:=1 to n do
begin
writeln('a[',i,']'); readln(a[i]);
end;
write('day vua nhap la:');
s:=0;
for i:=1 to n do
begin
write(a[i],' ');
s:=s+a[i];
if a[i] mod 2=0 then s1:=s1+a[i];
if a[i] mod 2<>0 then s2:=s2+a[i];
if a[i] mod 3=0 then s3:=s3+a[i];
end;
writeln;
writeln('tong bang:',s);
writeln('tong chan:',s1);
writeln('tong le:',s2);
writeln('tong chia het cho 3:',s3);
readln
end.
Câu 1 viết chương trình nhập vào 1 dãy n số nguyên bất kỳ .In ra màn hình tổng các số chia hết cho 2
uses crt;
var i,n:integer;
t:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap n:');readln(n);
t:=0;
for i:=1 to n do
begin
write('a[',i,']=');readln(a[i]);
if a[i] mod 2=0 then t:=t+a[i];
end;
write(t);
readln;
end.
viết chương trình nhập vào một dãy số nguyên n phần tử, n nhập từ bàn phím.
a) In ra màn hình dãy số vừa nhập xếp theo thứ tự tăng dần.
b) In ra màn hình các số nguyên tố trong dãy số vừa nhập và đếm xem đã nhập vào bao nhiêu số nguyên tố.
Viết chương trình nhập vào dãy số gồm có N phần tử a1, a2, a3,…,an (N<=100). Các phần tử của dãy số là các số nguyên (với n là số nguyên dương được nhập vào từ bàn phím). Thực hiện các yêu cầu sau:.
a. In ra màn hình giá trị của các phần tử vừa nhập
Tính tổng các số vừa nhập và in kết quả ra màn hình
Var a:array[1..100] of integer;
i,n:integer;
s:longint;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
s:=s+a[i];
End;
Write('Cac phan tu vua nhap la ');
For i:=1 to n do
Write(a[i]:8);
Writeln;
Write('Tong cua chung la ',s);
Readln
End.
Cho dãy N số nguyên ( với n nhập vào từ bàn phím) . Viết chương trình thực hiện các yêu cầu sau. a. Nhập vào dãy số n và giá trị từng phần của dãy. b. Xuất giá trị của dãy vừa nhập. c. Tính tổng các phần tử của dãy. d. In ra màn hình giá trị Max, Min của dãy. e. Tính tổng các phần tử dương của dãy. f. Tính tổng các phần tử âm của dãy. g. Tính tổng các phần tử chẵn của dãy. h. Tính tổng các phần tử lẻ của dãy. i. Sắp xếp các phần của dãy theo thứ tự giảm dần. k. Sắp xếp các phần của dãy theo thứ tự tăng dần.
Câu 1: Viết cú pháp lệnh khai báo biến mảng? Khai báo 2 biến x,y kiểu mảng có 50 phần tử nguyên. Câu 2: Viết chương trình nhập vào một dãy (mảng) gồm n số và in ra các số chia hết cho 3 đã nhập. Em hãy thực hiện các yêu cầu sau (không viết chương trình): - Em hãy xác định input, output của bài toán - Em hãy khai báo các biến sử dụng trong bài trên Câu 3: Viết chương trình nhập vào n, tính tổng S=1+2+..+n (bằng lệnh while) Giúp mình với đang cần gấp :
Viết chương trình nhập vào một số nguyên a bất kì hãy sắp xếp dãy số đã nhập và in ra màn hình các số chẵn
Viết chương trình nhập vào dãy N số nguyên lưu vào mảng A. In ra màn hình các số nguyên chia hết cho 3