Câu 3: Nhập một mảng gồm N phần tử.
A, tính tổng chẵn, tổng lẻ của các phấn tử trong mảng.
B, Tìm phần tử lớn nhất, nhỏ nhất trong mảng.
C, Tìm kiếm xem phần tử K nào đó có tồn tại trong mảng hay không?
giúp e với ạ
Câu 3: Nhập một mảng gồm N phần tử.
A, tính tổng chẵn, tổng lẻ của các phấn tử trong mảng.
B, Tìm phần tử lớn nhất, nhỏ nhất trong mảng.
C, Tìm kiếm xem phần tử K nào đó có tồn tại trong mảng hay không?
a:
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,t1,t2;
int main()
{
cin>>n;
t1=0;
t2=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0) t1=t1+x;
else t2=t2+x;
}
cout<<t1<<" "<<t2;
return 0;
}
Câu 3: Viết chương trình nhập vào một mảng gồm n phần tử.
a. Tính tổng các phần tử trong mảng
b. In ra tổng của các phần tử chẵn trong mảng.
c. Sắp xếp mảng giảm dần.
Giúp mik với !!! Bằng pascal nhé
uses crt;
var a:array[1..100]of integer;
i,n,t,t1,j,tam:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
t:=0;
for i:=1 to n do t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod 2=0 then t1:=t1+a[i];
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(t);
writeln(t1);
for i:=1 to n do write(a[i]:4);
readln;
end.
1. Viết chương trình nhập vào mảng gồm n số nguyên, - Đếm và đưa ra số phần tử chẵn của mảng - đưa ra số chẵn lớn nhất trong mảng - Tính tổng các số ở vị trí lẻ trong mảng - Tìm giá trị phần tử lẻ nhỏ nhất
uses crt;
var a:array[1..100]of integer;
i,n,dem,max,t,min,dem1:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
max:=-32000;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
dem:=dem+1;
if max<a[i] then max:=a[i];
end;
if dem=0 then writeln('Trong day khong co so chan')
else begin
writeln('So so chan la: ',dem);
writeln('So chan lon nhat la: ',max);
end;
t:=0;
for i:=1 to n do
if i mod 2=1 then t:=t+a[i];
writeln('Tong cac so o vi tri le la: ',t);
min:=maxint;
dem1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then
begin
inc(dem1);
if min>a[i] then min:=a[i];
end;
if dem1=0 then writeln('Trong day khong co so le')
else writeln('So le nho nhat la: ',min);
readln;
end.
Nhập vảo mảng gồm N số nguyên:
a) In ra màn hình các số chẵn có trong mảng.
b) Tính tổng các số lẻ có trong mảng.
c) Tìm giá trị lớn nhất và giá trị nhỏ nhất có trong mảng
Giúp mình vs mai mình kt rồi !
Program HOC24;
var min,max,n,i: integer;
t: longint;
a: array[1..1000] of integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Cac so chan trong mang la: ');
for i:=1 to n do if a[i] mod 2=0 then write(a[i],' ');
writeln;
t:=0;
for i:=1 to n do if a[i] mod 2=1 then t:=t+a[i];
writeln('Tong cac so le la: ',t);
min:=a[1]; max:=a[1];
for i:=1 to n do
begin
if a[i]>max then max:=a[i];
if a[i] <max then max:=a[i];
end;
writeln('Gia tri lon nhat la: ',max);
write('Gia tri nho nhat la:' ,min);
readln
end.
Cho mảng A gồm n phần tử là các số nguyên a, Nhập vào mảng A từ bàn phím b, tính tổng của các phần tử chẵn c, tính tổng của các phần tử lẻ d, đếm xem có bao nhiêu phần tử trong dãy chia hết cho 3
giúp em với ạ em đang thi hết môn cần gấp
Viết chương trình thực hiện các công việc sau:
a) Nhập một mảng 10 phần tử và hiển thị mảng vừa nhập ra màn hình.
b) Tìm phần tử nhỏ nhất trong mảng.
c) Đếm xem có bao nhiêu số lẻ và tính trung bình cộng các số lẻ trong mảng.
d) Sắp xếp mảng theo thứ tự tăng dần
Câu 4: (2 điểm)
Viết chương trình thực hiện các công việc sau:
a) Nhập vào từ bàn phím một xâu ký tự ST. Hiển thị xâu st ra màn hình.
b) Nhập ký tự x từ bàn phím, đếm trong xâu st có bao nhiêu ký tự x?
c++
Câu 4:
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
char x;
int main()
{
getline(cin,st);
d=st.length();
cout<<st<<endl;
cin>>x;
dem=0;
for (i=0; i<=d-1; i++) if (st[i]==x) dem++;
cout<<dem;
return 0;
}
Câu 4:
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
char x;
int main()
{
getline(cin,st);
d=st.length();
cout<<st<<endl;
cin>>x;
dem=0;
for (i=0; i<=d-1; i++) if (st[i]==x) dem++;
cout<<dem;
return 0;
}
-Viết chương trình:
a)Nhập vào mảng 1 chiều N phần tử nguyên(N<=100)
b)In mảng vừa nhập.
c)Tính tổng các phần tử lẻ/chẵn trong mảng
d)Đếm xem trong mảng có bao nhiều phần tử chia hết cho 3.
e)Tính tổng các phần tử trong mảng.
f)Sắp xếp các mảng theo thứ tự tăng dần.
Viết chương trình - nhập vào mảng 1 chiều gồm n số nguyên n nhỏ hơn hoặc bằng 100 - tính tổng các phần tử trong mảng -tính các tổng chẵn ,lẻ trong mảng
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t1,t2,t3;
int main()
{
cin>>n;
t1=0; t2=0; t3=0;
for (i=1; i<=n; i++)
{
cin>>x;
t1+=x;
if (x%2==0) t2+=x;
else t3+=x;
}
cout<<t1<<" "<<t2<<" "<<t3;
return 0;
}
Viết chương trình nhập vào một mảng;
a. Viết hàm tìm vị trí phần tử lớn nhất trong mảng vừa nhập.
b. Viết hàm chèn phần tử có giá trị X vào phía sau phần tử có giá trị lớn nhất trong mảng.
c. In ra mảng sau khi chèn phần tử X
Lấy một ví dụ giải thích cho ý a., ý b.