C++
viết chương trình nhập vào dãy số với n phần tử, tìm phần tử số chẵn lớn nhất cho biết vị trí các phần tử đó
Dãy số 21 17 20 53 49 12 phần tử 20 lớn nhất vị trí thứ 3 giải giúp mình với ạ
C++
Viết chương trình nhập vào dãy số n phần tử, đếm xem có bao nhiêu phần tử chia hết cho 3, cho biết vị trí các phần tử đó.
dãy số 3 7 20 5 9 12 phần tử 12 lớn nhất, vị trí thứ 6 giúp mình với ạ
2. Viết CT nhập vào dãy số nguyên có n phần tử. In ra vị trí các phần tử âm.
3. Viết CT nhập vào dãy số tự nhiên có n phần tử. In ra giá trị các phần tử ở vị trí lẻ.
4. Tìm phần tử lớn nhất và nhỏ nhất trong 1 dãy phần tử.
2:
uses crt;
var a:array[1..100]of integer;
n,i: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]<0 then write(i:4);
readln;
end.
sao bài này giống bài tập cô mình giao thế nhỉ:>
4
var max,min,n,i: integer;
a:array [1..100] of integer;
begin
write('nhap so phan tu: ');readln(n);
for i:=1 to n do
begin
write('a[',i,']=');readln(a[i]);
end;
max:=a[1];min:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
write('so lon nhat trong day la: ',max);writeln;
write('so nho nhat trong day la: ',min);writeln;
readln;
end.
viết chương trình nhập từ bàn phím một dãy số nguyên gồm 6 phần tử a. Tính tổng các phần tử có giá trị chẵn b. Tính tổng các phần tử có giá trị lẻ ở vị trí chắn c . Tìm phần tử có giá trị lớn nhất d . Tìm số phần tử có giá trị lớn hơn hoặc bằng
#include <bits/stdc++.h>
using namespace std;
long long a[6],i,t,t1;
int main()
{
t=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
if (a[i]%2==0) t=t+a[i];
}
t1=0;
for (i=1; i<=n; i++)
if ((a[i]%2!=0) and (i%2==0)) t1=t1+a[i];
cout<<t<<endl;
cout<<t1;
return 0;
}
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.
uses crt;
var a:array[1..200]of integer;
i,n,max:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('Gia tri lon nhat la: ',max);
write('Vi tri la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
readln;
end.
Hãy viết CT tính TBC của các phần tử trong dãy số và đếm xem có bao nhiêu phần tử ở vị trí chẵn ( với độ dài của dãy số được nhập vào từ bàn phím ) giúp mình với ạ :3
uses crt;
var a:array[1..100]of integer;
i,n,t,dem: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];
writeln(tb/n:4:2);
dem:=0;
for i:=1 to n do
if i mod 2=0 then dem:=dem+1;
writeln(dem);
readln;
end.
Viết chương trình nhập vào mảng a gồm n phần tử (n <40) n nhập từ bàn phím
Hãy in ra màn hình vị trí của phần tử có giá trị lớn nhất trong mảng nếu mảng có phần tử có cùng giá trị lớn nhất thì in ra màn hình của phần tử lớn nhất ở vị trí lớn nhất
#include <bits/stdc++.h>
using namespace std;
long long a[40],i,n,ln;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
{
cin>>a[i];
}
ln=a[1];
for (i=1; i<=n; i++) ln=max(ln,a[i]);
for (i=n; i>=1; i--)
if (ln==a[i])
{
cout<<i;
break;
}
return 0;
}
Cho dãy số A gồm N phần tử không sắp xếp theo thứ tự. Viết chương trình tính tổng các phẩn tử của dãy số, tìm phần tử có giá trị lớn nhất trong mảng, phẩn tử có giá trị nhỏ nhất trong mảng và vị trí xuất hiện của nó. Sắp xếp dãy số lại theo thứ tự tăng dần. Biết 0<N≤50.
uses crt;
var a:array[1..50]of int64;
i,n,t,max,min:int64;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
max:=a[1];
min:=a[1];
t:=0;
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
t:=t+a[i];
end;
writeln('Tong la: ',t);
writeln('So lon nhat la: ',max);
write('Vi tri la: ');
for i:=1 to n do
if a[i]=max then write(i:4);
writeln;
writeln('So nho nhat la: ',min);
write('Vi tri la: ');
for i:=1 to n do
if a[i]=min then write(i:4);
readln;
end.
Viết chương trình nhập vào 1 dãy số nguyên a gồm n phần tử(0<n<100),viết chương trình xử lý các câu sau:
a) Tìm và in ra màn hình số lớn nhất,bé nhỏ của dãy a và vị trí của các số đó
#include <bits/stdc++.h>
using namespace std;
long long a[100],n,i,ln,nn,vt1,vt2;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
ln=a[1];
nn=a[1];
for (i=1; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<ln<<" "<<nn;
return 0;
}
Var n,i,vtl,vtn,so max,min:integer;
Begin
Write('Nhap so luong so = ');readln(n);
vtl:=0;
vtn:=0;
max:=-32768;
min:=32767;
For i:=1 to n do
Begin
Write('Nhap vao so thu ',i);readln(so);
If so > max then
Begin
Max:=so;
vtl:=i;
End;
If so < min then
Begin
Min:=so;
vtn:=i;
End;
Writeln('So lon nhat la ',max,' tai vi tri thu ',i);
Write('So nho nhat la ',min,' tai vi tri thu ',i);
Readln;
End.