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.
const fi='bai1.inp';
fo='bai1.out';
var f1,f2:text;
a:array[1..100]of integer;
n,i,t,dem: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]);
t:=0;
dem:=0;
for i:=1 to n do
begin
if a[i] mod 2<>0 then t:=t+a[i]
else inc(dem);
end;
writeln(f2,'Tong cac so le la: ',t);
writeln(f2,'So so chan la: ',dem);
close(f1);
close(f2);
end.
mình ghi dư cái số 4 bên phần BAI7.INP nha mn
uses crt;
var a:array[1..250]of integer;
i,n,dem,t,t1,t2,t3,t4:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=250);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until (0<a[i]) and (a[i]<=500);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=1 then inc(dem);
writeln('So phan tu co gia tri le la: ',dem);
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+a[i];
writeln('Tong cac phan tu co chi so chan la: ',t);
t1:=0;
for i:=1 to n do
if i mod 2=1 then t1:=t1+a[i];
writeln('Tong cac phan tu co chi so le la: ',t1);
t2:=0;
for i:=1 to n do
if (i mod 2=0) and (a[i] mod 2=0) then t2:=t2+a[i];
writeln('Tong cac phan tu chan co chi so chan la: ',t2);
t3:=0;
for i:=1 to n do
if (i mod 2=1) and (a[i] mod 2=1) then t3:=t3+a[i];
writeln('Tong cac phan tu co chi so le la: ',t3);
t4:=0;
for i:=1 to n do
t4:=t4+a[i];
writeln('Trung binh cong cac so trong day la: ',t4/n:4:2);
readln;
end.
Bai 2:
uses crt;
var a:array[1..100]of integer;
i,n,t,nn:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
nn:=a[1];
for i:=1 to n do
if nn>a[i] then nn:=a[i];
write(nn);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,t,k:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
readln(k);
t:=0;
for i:=1 to n do
if a[i] mod k=0 then t:=t+a[i];
writeln(t);
readln;
end.
Uses crt;
Var A: array[1..100] of longint;
n,k,i,s: longint;
Begin
Clrscr;
Write(‘Nhap n,k: ‘); Readln(n,k);
s:=0;
For i:=1 to n do
Begin
Read(A[i]);
If A[i] mod k = 0 then s:=s+A[i];
End;
Write(s);
Readln
End.
const fi='tong.inp';
fo='tong.out';
var f1,f2:text;
a:array[1..100]of integer;
n,i,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]);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
const fi='bai25.inp';
fo='bai25.out';
var f1,f2:text;
a:array[1..1000]of integer;
i,n,dem,dem1,d:integer;
kt:boolean;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
dem:=0;
dem1:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem)
else inc(dem1);
writeln(f2,'So luong so chan la: ',dem);
writeln(f2,'So luong so le la: ',dem1);
d:=abs(a[2]-a[1]);
kt:=true;
for i:=2 to n do
if abs(a[i]-a[i-1])<>d then
begin
kt:=false;
break;
end;
if kt=true then writeln(f2,'Day la day cap so cong')
else writeln(f2,'Day khong la day cap so cong');
close(f1);
close(f2);
end.
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,k,t;
int main()
{
cin>>n>>k;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%k==0) t+=x;
}
cout<<t;
return 0;
}
uses crt;
var a:array[1..200]of integer;
n,i,k,t,t1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod k=0 then t1:=t1+a[i];
writeln('Tong cac phan tu le la: ',t);
writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);
readln;
end.
uses crt;
const fi='mang.txt';
var a:array[1..100]of integer;
i,n,t1,t2:integer;
f1:text;
begin
clrscr;
assign(f1,fi); rewrite(f1);
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]>0 then
begin
t1:=t1+a[i];
end;
if a[i]<0 then
begin
t2:=t2+a[i];
end;
end;
writeln(f1,'Tong cac so duong la: ',t1);
writeln(f1,'Tong cac so am la: ',t2);
if abs(t1)>abs(t2) then writeln(f1,'Gia tri tuyet doi cua ',t1,' lon hon gia tri tuyet doi cua ',t2)
else if abs(t1)<abs(t2) then writeln(f1,'Gia tri tuyet doi cua ',t2,' lon hon gia tri tuyet doi cua ',t1)
else writeln(f1,'Gia tri tuyet doi cua ',t1,' bang gia tri tuyet doi cua ',t2);
close(f1);
end.