Nhập vào 1 mảng gồm n phân tử thực hiện các công việc sau : + Sắp xếp thành dãy tăng dần + tính tổng các số dương chia hết cho 3 + in ra màn hình số nguyên tố
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.
Bài 1: Hãy viết chương trình con thực hiện các công việc sau trên mảng một chiều:
+ Nhập vào 1 mảng
+ In mảng + Sắp xếp mảng tăng dần
+ Tính tổng các phần tử trong mảng
+ Đếm các phần tử chia hết cho 3 trong mảng
+ Đếm các số âm, dương trong mảng
Bài 2: Viết chương trình con để tính diện tích các hình sau:
- Diện tích hình tam giác theo công thức herrong khi biết độ dài 3 cạnh a, b, c của tam giác. S=sqrt(p*(p-a)*(p-b)*(p-c)) với p=(a+b+c)/2
- Diện tích hình thang khi biết độ dài chiều cao h và 2 cạnh đáy a, b S=(a+b)*h/2 - Diện tích hình vuông khi biết độ dài cạnh.
Bài 3: Viết chương trình giải phương trình bậc 2 sử dụng chương trình con
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
N = int(input("Nhập số lượng phần tử của dãy N (>50): "))
while N <= 50:
N = int(input("Nhập lại số lượng phần tử của dãy N (>50): "))
# Nhập vào dãy số
danh_sach = []
for i in range(N):
danh_sach.append(int(input("Nhập số thứ %d: " % (i+1))))
# In ra dãy số vừa nhập
print("Dãy số vừa nhập:")
for i in danh_sach:
print(i, end=' ')
# Nhập vào số nguyên x
x = int(input("nNhập vào số nguyên x: "))
# In ra các số chia hết cho x
print("Các số chia hết cho x là:")
for i in danh_sach:
if i % x == 0:
print(i, end=' ')
Nhập mảng dãy số từ bàn phím a in ra tổng các số chia hết cho 3 trong dãy b in ra các số trong khoảng từ 50 đến 100 c sắp xếp dãy theo thứ tự tăng dần và in ra màn hình
Lập trình giải bài toán sau Nhập 1 mảng gồm N số nguyên từ bàn phím 1.In mảng vừa nhập,mỗi mảng cách nhau 5 vị trí 2.In ra tất cả các số dương trong mảng 3.Tính tổng các số chia hết cho 3 4.Sắp xếp mảng theo chiều giảm dần
uses crt;
var a:array[1..100]of integer;
i,n,t,j,tam:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:5);
writeln;
writeln('Cac so duong la: ');
for i:=1 to n do if (a[i]>0) then write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 3=0 then t:=t+a[i];
writeln(t);
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;
for i:=1 to n do write(a[i]:4);
readln;
end.
1.Viết chương trình nhập vào một dãy số gồm n phần tử.Sắp xếp dãy số theo thứ tự tăng dần sau đó in ra màn hình dãy số đã sắp xếp. 2.Viết chương trình nhập vào một dãy số gồm n phần tử. Sắp xếp dãy số theo thứ tự giảm dần sau đó in ra màn hình dãy số đã sắp xếp.(cứu mk với mai thi r ạ🥲
1)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] > a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep tang dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
2)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] < a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep giam dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
Đề 1 : Nhập từ bàn phím dãy số gồm phần tử ( n nhập từ bàn phím )
- Dòng 1: In ra dãy số đã sắp xếp theo thứ tự tăng dần
- Dòng 2: In ra các phần tử trong dãy số chia hết cho 3
- Dòng 3: Tính tổng các phân tử trong dãy số là số nguyên tố
Đề 2 ; Nhập từ bàn phím dãy số gồm phần tử ( n nhập từ bàn phím )
- Dòng 1: : In ra dãy số đã sắp xếp theo thứ tự giảm dần
- Dòng 2: In ra các phần tử trong dãy số chia hết cho 5
- Dòng 3: Tính tổng các phân tử trong dãy số là số chính phương
Đề 3 : Nhập từ bàn phím dãy số gồm phần tử ( n nhập từ bàn phím )
- Dòng 1: : In ra dãy số đã sắp xếp những số chia hết cho 5 đứng đầu dãy
- Dòng 2: In ra các phần tử trong dãy số chia hết cho 7
- Dòng 3: Tính tổng các phân tử trong dãy số là số đối xứng có trong dãy số
huhu giúp tớ với
-Nhập dãy số nguyên gồm n phân tử
-Xuất ra màn hình:
+Dòng 1: Các số chẵn của dãy số
+Dòng 2: Tổng các số lẻ
+Dòng 3: Số nhỏ nhất của dãy số
+Dòng 4: Sắp xếp dãy số tăng dần
Program HOC24;
var min,j,i,n,tg: integer;
t: longint;
a: array[1..1000] of integer;
begin
write('Nhap n: '); readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,': '); readln(a[i]);
end;
t:=0;
for i:=1 to n do if a[i] mod 2=0 then write(a[i],' ') else t:=t+a[i];
writeln; writeln('Tong cac so le la: ',t);
min:=a[1];
for i:=2 to n do if a[i]<min then min:=a[i];
writeln('So nhat nhat la: ',min);
for i:=1 to n do
for j:=i to n do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
for i:=1 to n do write(a[i],' ');
readln
end.
Uses crt;
var i,n,min,k,e,j: longint
a: array[1..100] of longint;
begin clrscr;
readln(n);
for i:=1 to n do read(n); readln;
for i:=1 to n do if(a[i] mod 2=0) then write(a[i],' ');
for i:=1 to n do if(a[i] mod 2<>0) then k:=k+a[i];
min:=a[i];
for i:=1 to n do if(min>a[i]) then min:=a[i];
writeln(min);
for i:=1 to n-1 do
for j:=i+1 to n do if a[j] <=a[i] then
begin e:= a[i];
a[i]:=a[j];
a[j]:=e; end;
for i:=1 to n do write(a[i],'');
readln;
end.
Viết chương trình nhập 1 mảng số nguyên dương gồm n phần tử
a, in ra màn hình mảng vừa nhập (bỏ qua phần này!)
b, nhập số nguyên dương k. tính tổng các số trong mảng LỚN hơn k.
c, tìm kiếm các cặp 2 phần tử liên tiếp có tổng chia hết cho 10. in ra màn hình các cặp số và vị trí của nó!.
d, tìm phần tử lớn nhất và số nguyên dương lớn nhất không xuất hiện trong mảng nhưng nhỏ hơn phần tử lớn nhất trong mảng.
e, tìm số xuất hiện nhiều nhất(lặp lại lắm nhất) và số lần xuất hiện của số đó trong mảng.( Nếu tìm được nhiều số có số lần xuất hiện bằng nhau thì chỉ cần in ra số tìm được đầu tiên ).
f, đếm xem trong mảng có bao nhiêu số thân thiện :)) ( Số thân thiện là số có nhiều hơn 1 chữ số và nó chia hết cho TỔNG các chữ số của nó).
----------làm bằng procedure và function giúp mình kaka------------
<3 Cảm ơn các procoder :))