Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
Câu 1:
uses crt;
var a:array[1..100]of integer;
n,i,tl,tc:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if abs(a[i])>=1000 then writeln('vui long nhap so co gia tri tuyet doi nho hon 1000');
until abs(a[i])<1000;
end;
{--------------------------xu-ly-----------------------------}
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i];
if a[i] mod 2=1 then tl:=tl+a[i];
end;
writeln('tong so nguyen chan cua day la: ',tc);
writeln('tong so nguyen le cua day la: ',tl);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
n,i:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------------xu-ly-----------------------------}
writeln('cac so nguyen am co trong day la: ');
for i:=1 to n do
if a[i]<0 then write(a[i]:4);
readln;
end.
Câu 3:
uses crt;
var a:array[1..100]of integer;
n,i,t:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------------xu-ly-----------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 3=0 then t:=t+a[i];
writeln('tong cac phan tu chia het cho 3 la: ',t);
readln;
end.
Câu 4:
uses crt;
var a,vt:array[1..100]of integer;
n,i,t,dem,j:integer;
min:int64;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if abs(a[i])>=1000 then writeln('vui long nhap so co gia tri tuyet doi nho hon 1000');
until abs(a[i])<1000;
end;
{--------------------------xu-ly-----------------------------}
min:=maxint;
for i:=1 to n do
if min>a[i] then min:=a[i];
dem:=0;
for i:=1 to n do
if a[i]=min then
begin
inc(dem);
vt[dem]:=i;
end;
writeln('so nho nhat la: ',min);
writeln('vi tri cua no trong day lan luot la: ');
for j:=1 to dem do
write(vt[j]:4);
readln;
end.
Câu 5:
uses crt;
var a,vt:array[1..100]of integer;
n,i,j,tam:integer;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if (n<=0) or (n>100) then writeln('ban da nhap sai, yeu cau ban nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if abs(a[i])>=1000 then writeln('vui long nhap so co gia tri tuyet doi nho hon 1000');
until abs(a[i])<1000;
end;
{--------------------------xu-ly-----------------------------}
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 so giam dan la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.
Cho mình hỏi nếu đếm các phần tử có giá trị lẻ trong xâu thì làm như thế nào vậy
uses crt;
var a:array[1..50]of integer;
t,i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=50);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until (0<=a[i]) and (a[i]<=32767);
end;
writeln('Day A=');
for i:=1 to n do
write(a[i]:4);
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);
writeln('Cac so le trong day A la: ');
for i:=1 to n do
if a[i] mod 2=1 then write(a[i]:4);
readln;
end.
Bài 2:
uses crt;
var a:array[1..199]of integer;
i,n:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------xuat-------------------------------}
for i:=1 to n do write(a[i]:4);
readln;
end.
Bài 3:
uses crt;
var a:array[1..199]of integer;
i,n,x,dem:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{----------------------------xu-ly-------------------------------}
write('x='); readln(x);
dem:=0;
for i:=1 to n do
if a[i]=x then inc(dem);
writeln('trong day co ',dem,' gia tri ',x);
readln;
end.
#include <iostream>
#include <fstream>
using namespace std;
long int x[4],n,a[5001],kt[5001],ktvt[5001],MAXtong,dem=0;
int TRY(int i)
{
for(int j=x[i-1]+1;j<=n;j++)
if(kt[a[j]]==0)
{
x[i]=j;
kt[a[j]]=1;
if(i==3)
{
if(a[x[3]]==(float)(a[x[2]]+a[x[1]])/2||a[x[2]]==(float)(a[x[3]]+a[x[1]])/2||a[x[1]]==(float)(a[x[2]]+a[x[3]])/2)
{
dem++;
if(a[x[1]]+a[x[2]]+a[x[3]]>MAXtong)
{
MAXtong=a[x[1]]+a[x[2]]+a[x[3]];
}
}
}
else
TRY(i+1);
kt[a[j]]=0;
}
}
int main()
{
ifstream f("boba.inp");
f>>n;
for(int i=1;i<=n;i++)
{
f>>a[i];
}
x[0]=0;
MAXtong=-1000000000;
fill_n(kt,1001,0);
TRY(1);
cout<<dem<<endl;
if(dem>0)
{
cout<<MAXtong;
}
return 0;
}
Mình mới đạt tới trình độ quy hoạch động nên bạn thông cảm
Xin lỗi bạn, mình không hỗ trợ C. mình chỉ biết pascal thôi
const fi='tamhop.inp';
fo='tamhop.out';
var f1,f2:text;
a:array[1..100]of integer;
n,i,j,k,dem,max,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
{--------------------------------xu-ly--------------------------------}
dem:=0; max:=0;
for i:=1 to n-2 do
begin
for j:=i+1 to n-1 do
begin
for k:=j+1 to n do
begin
if (a[i]=(a[j]+a[k])/2) or (a[j]=(a[i]+a[k])/2) or (a[k]=(a[i]+a[j])/2) then
begin
inc(dem);
t:=a[i]+a[j]+a[k];
if max<=t then max:=t;
end;
end;
end;
end;
writeln(f2,dem);
writeln(f2,max);
close(f1);
close(f2);
end.
Bạn ơi! Mình viết code thôi, vì chưa có thời gian nên mình chưa test lại, bạn test lại giúp mình, nếu sai thì báo mình nha! (Bạn cố sữa lỗi trước nhé!)
program abc;
uses crt;
var
a: array [1..100] of integer;
i, n, d, d2, d5: integer;
begin
clrscr;
write ('Nhap n: ');
readln (n);
for i:=1 to n do
begin
write ('Nhap so thu ', i, ': ');
readln (a[i]);
end;
d:=0; d2:=0; d5:=0;
for i:=1 to n do
begin
if a[i] <0 then d:=d+1;
if a[i] mod 2 = 0 then d2:=d2+1;
if a[i] mod 5 = 0 then d5:=d5+1;
end;
writeln ('Co ', d, ' so am trong mang.');
writeln ('Co ', d2, ' so chia het cho 2.');
writeln ('Co ', d5, ' so chia het cho 5.');
writeln;
writeln ('Nhan Enter de ket thuc chuong trinh!');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
double xa,ya,xb,yb,xc,yc,ab,ac,bc,am;
int main()
{
cin>>xa>>ya>>xb>>yb>>xc>>yc;
ab=sqrt(pow(xa-xb,2)+pow(ya-yb,2));
ac=sqrt(pow(xa-xc,2)+pow(ya-yc,2));
bc=sqrt(pow(xb-xc,2)+pow(yb-yc,2));
cout<<"AB="<<fixed<<setprecision(2)<<ab<<endl;
cout<<"AC="<<fixed<<setprecision(2)<<ac<<endl;
cout<<"BC="<<fixed<<setprecision(2)<<bc<<endl;
am=((2*(ac*ac+bc*bc)-ab*ab)/4);
cout<<"AM="<<fixed<<setprecision(2)<<sqrt(am)<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
double xa,ya,xb,yb,xc,yc,ab,ac,bc;
int main()
{
cin>>xa>>ya>>xb>>yb>>xc>>yc;
ab=(sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)));
ac=(sqrt((xa-xc)*(xa-xc)+(ya-yc)*(ya-yc)));
bc=(sqrt((xb-xc)*(xb-xc)+(yb-yc)*(yb-yc)));
p=(ab+bc+ac)/2;
s=sqrt(p*(p-ab)*(p-ac)*(p-bc));
cout<<"Dien tich la:"<<fixed<<setprecision(2)<<s<<endl;
cout<<"Duong cao ung voi dinh A la:"<<fixed<<setprecision(2)<<2*s/bc<<endl;
cout<<"Duong cao ung voi dinh B la:"<<fixed<<setprecision(2)<<2*s/ac<<endl;
cout<<"Duong cao ung voi dinh C la:"<<fixed<<setprecision(2)<<2*s/ab<<endl;
return 0;
}