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.
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long a[250],i,n,k;
int main()
{
cin>>n>>k;
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]==k) cout<<i<<" ";
return 0;
}
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long a[250],i,n,k;
int main()
{
cin>>n>>k;
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]==k) cout<<i<<" ";
return 0;
}
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long a[250],i,n,k;
int main()
{
cin>>n>>k;
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]==k) cout<<i<<" ";
return 0;
}
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long a[250],i,n,k;
int main()
{
cin>>n>>k;
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]==k) cout<<i<<" ";
return 0;
}
uses crt;
var a:array[1..1000]of integer;
i,n,k,dem: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);
for i:=1 to n do
if a[i]=k then
begin
writeln(i);
break;
end;
dem:=0;
for i:=1 to n do
if a[i]=k then inc(dem);
if dem>0 then writeln('Co ',dem,' phan tu bang ',k)
else writeln('Khong co phan tu nao bang ',k);
readln;
end.
program bai_2;
uses crt;
var a:array[1..100]of byte;
n,i,j,tam,vt,vt2,x,x2,k,ch:byte;
procedure yc1;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do write(a[i]:3);
end;
procedure yc2;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
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('mang a:');for i:=1 to n do write(a[i]:3);
end;
procedure yc3;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
write('nhap so x:');readln(x);
for i:=n downto 1 do
if a[i]=x then vt:=i;if a[i]=x then writeln('vi tri cua ',x,' trong mang a la:',vt);writeln;
if a[i]<>x then writeln('khong tim thay ',x,' trong day so tren');writeln;
end;
procedure yc4;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
write('nhap so x2:');readln(x2);
for i:=n downto 1 do
if a[i]=x2 then vt2:=i;if x>0 then
begin
for i:=vt2 to n-1 do a[i]:=a[i+1];
for i:=1 to n-1 do write(a[i]:3);
end
else if a[i]<>x2 then write('khong tim thay ',x2,' trong day so tren');
end;
procedure yc5;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
write('nhap vi tri:');readln(vt);
for i:=1 to n do
if (vt=i) then writeln('phan tu o vi tri ',vt,' la:',a[vt]:3);
for i:=vt to n-1 do a[i]:=a[i+1];
for i:=n downto vt+1 do a[i]:=a[i-1];
write('nhap so can sua:');readln(a[vt]);
writeln('day so sau khi sua la:');
for i:=1 to n do write(a[i]:3); writeln;
end;
procedure yc6;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
write('nhap vi tri can chen k:');readln(k);
for i:=n+1 downto k+1 do a[i]:=a[i-1];
write('nhap so can chen vao day:');readln(a[k]);
writeln('day so sau khi chen ',a[k],' vao day la:');
for i:=1 to n+1 do write(a[i]:3);writeln;
end;
procedure yc7;
begin
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:3);
writeln;
end;
BEGIN
clrscr;
while ch<8 do
begin
clrscr;
writeln('CHON MOT TRONG CAC SO SAU:');
writeln('1.NHAP DAY SO:');
writeln('2.SAP XEP DAY SO:');
writeln('3.TIM MOT SO:');
writeln('4.XOA MOT SO:');
writeln('5.SUA MOT SO:');
writeln('6.CHEN MOT SO:');
writeln('7.IN DAY SO:');
writeln('8.THOAT KHOI CHUONG TRINH:');
write('nhap so co yeu cau ban muon lam:');readln(ch);
if ch<8 then
begin write('nhap so n:');readln(n); end;
case ch of
1:yc1;
2:yc2;
3:yc3;
4:yc4;
5:yc5;
6:yc6;
7:yc7;
end;
readln;
end;
readln;
end.
Program HOC24;
var i,n,k: integer;
a: array[1..20] of integer;
begin
write('Nhap n: '); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
write('Vi tri cac phan tu co gia tri bang ',k,': ');
for i:=1 to n do if a[i]=k then write(i,' ');
writeln;
for i:=1 to n do if a[i]=k then a[i]:=-k;
write('Mang sau khi thay the la: ');
for i:=1 to n do write(a[i],' ');
readln
end.