Viết chương trình nhập vào 1 dãy số xóa bớt các số lẻ. Xuất kết quả dưới dạng đối xứng của phần còn lại.
VD: 1 2 4 5 6 \(\rightarrow\) 2 4 6 6 4 2
Viết chương trình PYTHON nhập vào 1 dãy số, xoá bỏ các số lẻ, xuất kết quả dưới dạng đối xứng của phần còn lại
REFER
uses crt;
var a:array[1..255]of byte;
n,i,kt:integer;
st,st1:string;
begin
clrscr;
write('nhap chieu dai day so:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------xu-ly---------------------------------}
st:=''
kt:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
str(a[i],st1);
kt:=1;
st:=st+st1;
end;
if kt>0 then
begin
write('doi xung cua cac so chan la: ');
for i:=1 to length(st) do
write(st[i]:4);
for i:=length(st) downto 1 do
write(st[i]:4);
end;
readln;
end.
Nhập vào 1 số, xóa bớt các số chẵn. Xuất kết quả dưới dạng đối xứng của phần còn lại
VD: 1 2 4 5 6 \(\rightarrow\) 1 5 51
uses crt;
var st,st1,st2:string;
a:array[1..255]of integer;
n,d,i,dem,x,kt:integer;
begin
clrscr;
write('nhap so n:'); readln(n);
str(n,st);
d:=length(st);
for i:=1 to d do
val(st[i],a[i],x);
st2:='';
dem:=0;
kt:=0;
for i:=1 to d do
if a[i] mod 2<>0 then
begin
kt:=1;
dem:=dem+1;
str(a[i],st1);
st2:=st2+st1;
end;
if kt>0 then
begin
write('doi xung cua phan con lai sau khi xoa bot cac so chan la: ');
for i:=1 to dem do
write(st2[i]);
for i:=dem downto 1 do
write(st2[i]);
end;
readln;
end.
uses crt;
var a:array[1..255]of byte;
n,i,kt:integer;
st,st1:string;
begin
clrscr;
write('nhap chieu dai day so:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------xu-ly---------------------------------}
st:='';
kt:=0;
for i:=1 to n do
if a[i] mod 2=1 then
begin
str(a[i],st1);
kt:=1;
st:=st+st1;
end;
if kt>0 then
begin
write('doi xung cua cac so le la: ');
for i:=1 to length(st) do
write(st[i]:4);
for i:=length(st) downto 1 do
write(st[i]:4);
end;
readln;
end.
Viết chương trình nhập vào dãy số có n số, xuất ra màn hình tổng các số chia hết cho 2.
Ví dụ nhập n = 5
1 2 3 4 6
Xuất: tong cac so chia het cho 2 la: 12
Var s,n,i,so:integer;
Begin
Write('Nhap so luong so n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i)readln(so);
If so mod 2 = 0 then s:=s+so;
End;
Write('Tong cac so chan la ',s);
Readln;
End.
Program HOC24;
var i,n,t: integer;
a: array[1..32000] of integer;
begin
write('Nhap n= '); readln(n);
for i:=1 to n do if i=n then readln(a[i]) else read(a[i]);
t:=0;
for i:=1 to n do if a[i] mod 2=0 then t:=t+a[i];
write('Tong cac so chia het cho 2 la: ',t);
readln
end.
Viết chương trình nhập vào số nguyên dương n bất kỳ. Xuất ra trên màn hình kết quả tổng của dãy số sau: A = 1 + 2 + 3 + 4 + … + n Input: n = 5 Output: A = 15
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
s:=s+i;
writeln(s);
readln;
end.
viết chương trình
-nhập mãng n phần tử
-in mãng
-sắp xép các phần tử tăng dần
-in kết quả sau khi sắp xếp
n=6
cac số:3,5,1,4,2,6
mảng 1 2 3 4 5 6
Yêu cầu: Viết chương trình nhập vào số nguyên. Xóa các phần tử chia hết cho 3 của dãy và in ra dãy sau khi xóa. Sau đó lại xóa các phần tử chia hết cho 5 trong dãy còn lại và in ra dãy
Dữ liệu:
Dòng đầu tiên ghi số nguyên dương n (0<n<=105) ,
Dòng 2 ghi n số nguyên dương 64 bit cách nhau một dấu cách trống.
Kết quả:
Dòng đầu tiên ghi dãy sau khi xóa đi các phần tử chia hết cho 3,
Dòng thứ hai ghi dãy sau khi xóa hết các phần tử chia hết cho cả 3 và 5.
C++.Mong mn giúp
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll i, j, n, a[1000005], dem = 0, m;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] % 3 == 0)
{
n--;
i--;
}
}
for (i = 1; i <= n; i++)
{
cout << a[i] << " ";
}
cout<<endl;
for(i=1;i<=n;i++)
{
if(a[i]%5==0)
{
for(j=i;j<=n;j++)
{
a[j]=a[j+1];
}
n--;
i--;
}
}
for(i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
Viết chương trình Pascal, nhập vào một dãy số nguyên N phần tử, xuất radãy vừa nhập theo thứ tự tăng dần. Giá trị của N và các phần tử của dãy số đượcnhập từ tệp Cau4.Inp. Dữ liệu xuất ra trên tệp Cau4.Out. Ví dụ:
câu 4 input: |
4 6 8 7 55 9 8 7 6 56 4 5 6 7 8 97 50 40 60 80 35 35 1010 20 12 0 3 45 15 60 38 90 70 |
câu 4 output: |
4 5 6 7 85 5 6 7 8 96 4 5 6 7 8 97 10 35 35 40 50 60 8010 0 3 12 15 20 38 45 60 70 90 |
uses crt;
var a:array[1..100]of integer;
i,n,tam,j:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
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:=n downto 1 do
write(a[i]:4);
readln;
end.
Bài 1: Viết chương trình nhập vào 1 dãy số nguyên xuất dãy số đó ra màn hình tính tích các số chẵn và xuất ra màn hình.
Bài 2: Viết chương trình nhập 1 dãy số nguyên, xuất dãy số đó ra màn hình tính tổng các số chẵn các số lẻ và xuất ra màn hình.
program timtich;
uses crt;
var i,n:integer;
tich:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:4);
tich:=1;
writeln;
for i:=1 to n do
if a[i] mod 2=0 then tich:=tich*a[i];
writeln('tich ca phan tu chan cua mang la:',tich);
readln;
end.
program timtong;
uses crt;
var i,n:integer;
tong:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:4);
tong:=0;
writeln;
for i:=1 to n do
if a[i] mod 2=0 then tong:=tong+a[i];
writeln('tong cac phan tu chan cua mang la:',tong);
tong:=0;
writeln;
for i:=1 to n do
if a[i] mod 2=1 then tong:=tong+a[i];
writeln('tong cac phan tu le cua mang la:',tong);
readln;
end.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
s:=1;
for i:=1 to n do
if a[i] mod 2=0 then s:=s*a[i];
writeln(s);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,t1,t2:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t1:=0;
t2:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then t1:=t1+a[i]
else t2:=t2+a[i];
end;
writeln('Tong cac so chan la: ',t1);
writeln('Tong cac so le la: ',t2);
readln;
end.
1 Nhập dãy số nguyên gồm n phần tử viết chương trình in ra những số có giá trị lẻ 2 nhập vào dãy số nguyên gồm n phần tử viết chương trình tính tổng các số chẵn có trong mảng 3 nhập vào dãy số nguyên gồm n phần tử viết chương trình tính tổng các số lẻ có trong mảng
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:4);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2=0 then write(a[i]:4);
readln;
end.
Bài 3:
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] mod 2<>0 then t:=t+a[i];
writeln(t);
readln;
end.