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.
program mang;
uses crt;
var n,i:integer;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so phan tu :');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(n);
end;
for i:=1 to n do
write(a[i]:3);
readln;
end.
theo C++ nhé bạn
#include<bits/stdc++.h>
using namespace std;
int a[100],n,i;
int main()
{
cout<<"hay nhap so phan tu cua mang: ";
cin>>n;
cout<<"hay nhap gia tri cac phan tu cua mang: ";
for(i=1;i<=n;i++) cin>>a[i];
cout<<"gia tri cac phan tu trong mang la: ";
for(i=1;i<=n;i++) cout<<a[i]<<" ";
return 0;
}
Câu 1:
program mangsonguyen;
var
a: array[1..100] of integer;
i, n: integer;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Mang vua nhap la:');
for i := 1 to n do
write(a[i], ' ');
end.
Câu 2:
program trungbinhcong;
var
a: array[1..100] of integer;
i, n, k, sum: integer;
avg: real;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Nhap so k: ');
readln(k);
sum := 0;
for i := 1 to n do
begin
if a[i] <= k then
sum := sum + a[i];
end;
if sum > 0 then
begin
avg := sum / n;
writeln('Trung binh cong cac phan tu co gia tri <= ', k, ' la: ', avg:0:2);
end
else
begin
writeln('Khong co phan tu nao co gia tri <= ', k);
end;
end.
Câu 3:
program DemSoNguyenTo;
var
a: array [1..100] of integer;
i, j, n, count: integer;
laSoNguyenTo: boolean;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
write('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
count := 0;
writeln('Cac so nguyen to trong mang la: ');
for i := 1 to n do
begin
laSoNguyenTo := true;
for j := 2 to (a[i] div 2) do
begin
if (a[i] mod j = 0) then
begin
laSoNguyenTo := false;
break;
end;
end;
if laSoNguyenTo and (a[i] > 1) then
begin
writeln(a[i]);
count := count + 1;
end;
end;
writeln('Tong so cac so nguyen to la: ', count);
readln;
end.
Bài 2:
uses crt;
var x,i,n,dem:integer;
begin
clrscr;
readln(n);
dem:=0;
for i:=1 to n do
begin
readln(x);
if x mod 2=0 then inc(dem);
end;
writeln(dem);
readln;
end.
Câu 1:
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cac so trong mang la: ',t);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('Tong cac so chan la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long i,n,dem;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
int x=sqrt(i);
if (x*x==i)
{
dem++;
cout<<i<<" ";
}
}
cout<<endl;
cout<<dem;
return 0;
}
bạn ơi cái code này hơi chậm, bạn có thể sử dụng code này :)
#include <bits/stdc++.h>using namespace std;
int main(){
long long i;
cin >> i;
long long n = 1;
int counter = 0;
int additional = 3;
while (n<=i){
counter = counter +1;
n= n + additional;
additional = additional + 2;
}
cout << counter;
}
Câu 1:
uses crt;
var s:string;
i,d,dem:integer;
begin
clrscr;
write('nhap xau S:'); readln(s);
d:=length(s);
dem:=0;
for i:=1 to d do
if s[i]='a' then inc(dem);
writeln('so lan xuat hien cua chu a trong xau ',s,' la: ',dem);
readln;
end.
Câu 2:
uses crt;
var a:array[1..99]of integer;
n,i,k:integer;
s:longint;
begin
clrscr;
repeat
write('nhap n='); readln(n);
if n>=100 then writeln('nhap lai');
until n<100;
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if a[i]>=3000 then writeln('nhap lai');
until a[i]<3000;
end;
write('nhap so k:'); readln(k);
s:=1;
for i:=1 to n do
if k mod a[i]=0 then s:=s*a[i];
writeln('tich cac uoc cua ',k,' trong day la: ',s);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem,t,j,t1;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++)
{
t=0;
for (j=1; j<=a[i]-1; j++)
if (a[i]%j==0) t+=j;
if (t==a[i]) dem++;
}
cout<<dem<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) t1+=a[i];
cout<<t1;
return 0;
}
```pascal
program TimSoNguyenTrongSoN;
uses crt;
procedure TimSoNguyenTrongSoN(n: integer);
var
n_str: string;
so_nguyen_xuat_hien: array of integer;
temp: string;
i, j, so: integer;
begin
n_str := IntToStr(n);
SetLength(so_nguyen_xuat_hien, 0);
for i := 1 to Length(n_str) do
begin
temp := '';
for j := i to Length(n_str) do
begin
temp := temp + n_str[j];
if TryStrToInt(temp, so) then
begin
SetLength(so_nguyen_xuat_hien, Length(so_nguyen_xuat_hien) + 1);
so_nguyen_xuat_hien[Length(so_nguyen_xuat_hien) - 1] := so;
end;
end;
end;
writeln('Cac so nguyen xuat hien trong so ', n, ' la:');
for i := 0 to Length(so_nguyen_xuat_hien) - 1 do
begin
writeln(so_nguyen_xuat_hien[i]);
end;
end;
var
n: integer;
begin
clrscr;
write('Nhap vao so n: ');
readln(n);
TimSoNguyenTrongSoN(n);
readln;
end.
```
sao mình ko chạy được v bạn