Lập trình nhập một mảng gồm n số nguyên từ bàn phím
1.In mảng ra màn hình,các phần tử cách nhau 5 vị trí
2.Tìm và in ra các số dương trong mảng
3.Sắp xếp mảng theo thứ tự các số chẵn lên đầu,số lẻ xuống cuối
Lập trình nhập một mảng gồm n số nguyên từ bàn phím
1.In mảng ra màn hình,các phần tử cách nhau 5 vị trí
2.Tìm và in ra các số chẵn âm trong mảng
3.Sắp xếp mảng theo thứ tự các số dương lên đầu,các số âm xuống cuối
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i;
int main()
{
cin>>n;
for (i=1;i<=n; i++) cin>>a[i];
for (i=1;i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
for (i=1; i<=n; i++)
if (a[i]%2==0 && a[i]<0) cout<<a[i]<<" ";
cout<<endl;
for (i=1; i<=n; i++)
if (a[i]>0) cout<<a[i]<<" ";
for (i=1; i<=n; i++)
if (a[i]==0) cout<<a[i]<<" ";
for (i=1; i<=n; i++)
if (a[i]<0) cout<<a[i]<<" ";
return 0;
}
Lập trình nhập 1 mảng gồm n ký tự từ bàn phím
1.In mảng ra màn hình,các phần tử cách nhau 5 vị trí
2.Tìm và in ra các chữ viết hoa từ A->Z trong mảng
3.Đếm và in các chữ số thập phân(các chữ số 0->9) trong mảng ra
Nhập 1 mảng số nguyên từ bàn phím
1,In mảng vừa nhập ra màn hình,mỗi phần tử cách nhau 5 vị trí
2,Đếm và in ra các số chẵn âm
3,Đếm xem trong mảng có bao nhiêu phần tử bằng với 1 sô k được nhập từ bàn phím
4,Tìm giá trị nhỏ nhất của mảng
5,In ra toàn bộ các số nguyên dương có trong mảng
6,Sắp xếp mảng theo chiều giảm dần
Mọi ng giúp tui với!!!!
Nhập 1 mảng số nguyên từ bàn phím
1,In mảng vừa nhập ra màn hình,mỗi phần tử cách nhau 5 vị trí
2,Đếm và in ra các số chẵn âm
3,Đếm xem trong mảng có bao nhiêu phần tử bằng với 1 sô k được nhập từ bàn phím
4,Tìm giá trị nhỏ nhất của mảng
5,In ra toàn bộ các số nguyên dương có trong mảng
6,Sắp xếp mảng theo chiều giảm dần
1.Nhập một mảng gồm n số nguyên từ bàn phím 2.In mảng vừa nhập ra màn hình theo chiều ngang các phần tử cách nhau 5 vị trí 3.Đếm và in ra các số lử âm ra dòng tiếp theo 4.Tính tổng các số chẵn 5.Sắp xếp theo chiều giảm dần Mn giúp e vs ạ!!!!
#include <bits/stdc++.h>
using namespace std;
long long a[10000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
t=0;
for (i=1; i<=n; i++) if (a[i]%2==0) t+=a[i];
cout<<"Tong cac so chan la: "<<t<<endl;
sort(a+1,a+n+1);
cout<<"Day so giam dan la: ";
for (i=n; i>=1; i--) cout<<a[i]<<" ";
return 0;
}
Bài 1:Nhập 1mảng có n số nguyên từ bàn phím
1.In mảng vừa nhập
2.Đếm và in ra các số chẵn 3.Tính tổng các số lẻ
4.Đếm và in ra các số lẻ không chẵn
Bài 2:Nhập 1 mảng gồm n số nguyên từ bàn phím.In mảng vừa nhập các phần tử cách nhau 5 khoảng trống.Tìm max,min của mảng
Bài 3:Nhập 1 mảng gồm n số thực từ bàn phím.In mảng vừa nhập,mỗi mảng cách nhau 4 vị trí.In ra màn hình tất cả các số âm in trong mảng.Tính tổng các số âm đó
Bài 2:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,ln,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
ln=a[1];
nn=a[1];
for (i=2; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<ln<<" "<<nn;
}
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.
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.
Cho mảng một chiều gồm n phần tử thuộc kiểu số nguyên viết chương trình nhâp mảng xuất dữ liệu của mảng đếm và in ra các phần tử chính phương trong mảng sắp xếp các phần tử mảng theo thứ tự số chẵn tăng số lẻ giảm