viết chương trình thực hiện lên màn hình các số nguyên dương nhỏ hơn hoặc bằng 20 theo thứ tự giảm dần
Viết chương trình nhập từ bàn phím số nguyên dương N (N<=100) và dãy A gồm N số nguyên A1, A2, …AN. Tìm và in ra số nhỏ nhất của dãy số vừa nhập? Sắp xếp dãy số A theo thứ tự giảm dần và in ra màn hình. Input: Số nguyên dương N và dãy số A gồm N số nguyên dương a1, a2, …, an. Output: In ra Phần tử nhỏ nhất của dãy số đó. Sắp xếp dãy số A theo thứ tự giảm dần và in ra màn hình.
uses crt;
var a:array[1..100]of integer;
i,n,min,tam,j:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('Gia tri nho nhat la: ',min);
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.
Viết chương trình nhập vào từ bàn phím một số nguyên dương n, in ra màn hình các số lẻ nhỏ hơn hoặc bằng số nguyên dương n. Chương trình yêu cầu nhập lại nếu n <=0. (Sử dụng câu lệnh While … do)
program Le_Nho_Hon_Hoac_Bang_n;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
while n <= 0 do
begin
writeln('So ban nhap khong hop le. Xin vui long nhap lai: ');
readln(n);
end;
clrscr;
writeln('Cac so le nho hon hoac bang ', n, ' la:');
i := 1;
while i <= n do
begin
if i mod 2 <> 0 then
writeln(i);
i := i + 1;
end;
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.
hãy viết 1 chương trình nhập dãy số gồm n số nguyên (n<=100).Viết chương trình sắp xếp các phần tử chẳn lên đầu dãy theo thứ tự tăng dần.các phần tử lẻ ở cuối dãy theo thứ tự giảm dần
#include <bits/stdc++.h>
using namespace std;
long long a[100],b[100],c[100],n,i,dem1,dem2;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
dem1=0;
dem2=0;
for (i=1; i<=n; i++)
{
if (a[i]%2==0)
{
dem1++;
b[dem1]=a[i];
}
else
{
dem2=0;
c[dem2]=a[i];
}
}
sort(b+1,b+dem1+1);
sort(c+1,c+dem2+1);
for (i=1; i<=dem1; i++)
cout<<b[i]<<" ";
for (i=dem2; i>=1; i--)
cout<<c[i]<<" ";
return 0;
}
Viết chương trình nhập vào một số nguyên dương n từ bàn phím 912.10n
Rồi đếm và xuất ra màn hình các số nguyên tố nhỏ hơn hoặc bằng n được viết trên
một hàng với mỗi số cách nhau ít nhất là một khoảng trắng.
#include <bits/stdc++.h>
using namespace std;
long long i,n,kt,j;
int main()
{
cin>>n;
for (i=2; i<=n; i++)
{
kt=0;
for (j=2; j*j<=i; j++)
if (i%j==0) kt=1;
if (kt==0) cout<<i<<" ";
}
return 0;
}
Viết chương trình nhập vào 1 số nguyên n
không âm, in ra màn hình số lượng số dương lớn hơn n và nhỏ hơn hoặc bằng n^2
ngôn ngữ c++
help me plssssssssssssssssssssssssssssssssssssssssss
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Nhap vao mot so nguyen khong am: ";
cin >> n;
int count = 0;
for (int i = n + 1; i <= n * n; i++) {
if (i > 0) {
count++;
}
}
cout << "So luong so duong lon hon " << n << " va nho hon hoac bang " << n * n << " la: " << count << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
long long n;
cin>>n;
cout <<n*n-n<<endl;
return 0;
}
Viết chương trình nhập vào 1 số nguyên N in ra màn hình các số hoàn chỉnh nhỏ hơn hoặc bằng N.
Helpppppp meeeeeeee!!!!
{program bt_1;
uses crt;
Var:S ,n, i, j:longint;
Begin
clrsr;
Write('Nhap n');Readln(n);
For i:=1 to n do
Begin
S:=0;
For j:=0 to i do
if i mod j:=0 then S:=S+j;
if S=2*i then Write (i:5);
end;
readln;
end.
}
Viết chương trình pascal nhập vào một mảng số nguyên B số lượng phần tử là m nhập từ bàn phím
+ sắp xếp mảng theo thứ tự giảm dần rồi in mảng đã sắp xếp ra màn hình
Var a:array[1..1000] of integer;
i,m,tam:integer;
Begin
Write('m = ');readln(m);
For i:=1 to m do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to m do
If a[i] < a[i+1] then
Begin
tam:=a[i];
a[i]:=a[i+1];
a[i+1]:=tam;
End;
Write('Mang sau khi sap xep: ');
For i:=1 to m do
Write(a[i]:8);
Readln;
End.
viết chương trình nhấp số tự nhiên N từ bàn phím và in ra màn hình các số lẻ nhỏ hơn hoặc bằng N
#include <bits/stdc++.h>
using namespace std;
int i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
if (i%2==1) cout<<i<<" ";
return 0;
}