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.
VD chính xác :
m1.inp | m1.out |
5 -2 3 5 4 -7 |
-2 3 5 4 -7 -7 -2 3 4 5 |
Lời giải :
program hotrotinhoc;
const fi='m1.inp';
fo='m1.out';
var f: text;
i,n,tg : integer;
a: array[1..32000] of integer;
procedure ip;
begin
assign(f,fi);
reset(f);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
close(f);
end;
procedure out;
begin
for i:=1 to n do
write(f,a[i],' ');
writeln(f);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
for i:=1 to n do write(f,a[i],' ');
close(f);
end;
begin
ip;
out;
end.
uses crt;
var a,b:array[1..100]of integer;
n,i,dem,max,tam,j:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac so chia het cho 4 la: ');
for i:=1 to n do
if a[i] mod 4=0 then write(a[i]:4);
writeln;
dem:=0;
for i:=1 to n do
if a[i] mod 7=0 then
begin
inc(dem);
b[dem]:=a[i];
end;
max:=b[1];
for i:=1 to dem do
if max<b[i] then max:=b[i];
writeln('So lon nhat chia het cho 7 la: ',max);
writeln('Cac chi so cua no trong day A la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
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 sau khi sap xep giam dan la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.
Sữa lỗi:
phần khai báo:a:array[1..250] of integer (ngoặc vuông ko phải ngoặc tròn)
Câu 1:
#include <bits/stdc++.h>
using namespace std;
long long i,n,k,dem,x;
int main()
{
cin>>n;
cin>>k;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x==k) dem++;
}
cout<<dem;
return 0;
}
uses crt;
var a:array[1..1000]of integer;
i,n,k,t: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 k=0 then t:=t+a[i];
writeln('Tong cac so la boi cua ',k,' la: ',t);
readln;
end.
tham khảo
Program Hotboy;
Uses crt;
Var A:array[1..100] of integer;
I,n : byte;
S:real;
Begin
Clrscr ;
S:=1;
Write('nhao so phan tu trong day'); 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 5 =0 then
S:=S* A[i] ;
Writeln('Tong cac phan tu chia het cho 5 trong mang la',S);
Readln
End.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
t:=1;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t*a[i];
writeln(t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,dem,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac so chan la: ');
dem:=0;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
write(a[i]:4);
t:=t+a[i];
inc(dem);
end;
writeln('Tong cac so chan la: ',t);
writeln('Trong day co ',dem,' so chan');
readln;
end.
Câu 3:
#include <bits/stdc++.h>
using namespace std;
string a[1000];
int n,i,dem;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
if (a[i]=='a') dem++;
}
cout<<dem;
return 0;
}