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;
i,n,t,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
s:=1;
dem:=0;
for i:=1 to n do
if a[i] mod 3=0 then
begin
inc(dem);
t:=t+a[i];
s:=s*a[i];
end;
if dem=0 then writeln('Khong co so chia het cho 3 trong day')
else begin
writeln('Tong cac so chia het cho 3 la: ',t);
writeln('Tich cac so chia het cho 3 la: ',s);
end;
readln;
end.
Câu 2:
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;
dem:=0;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('So so chan la: ',dem);
writeln('Tong cac so chan la: ',t);
readln;
end.
uses crt;
var t,n,i,dem:integer;
begin
clrscr;
readln(n);
dem:=0;
t:=0;
for i:=0 to n do
if i mod 2=0 then
begin
t:=t+i;
dem:=dem+1;
end;
writeln(dem,' ',t);
readln;
end.
Câu 2:
a) Mô tả thuật toán
-Bước 1: Nhập n và nhập dãy số
-Bước 2: dem←0; i←1; t←0;
-Bước 3: Nếu a[i] mod 2=0 thì dem←dem+1 và t←t+a[i];
-Bước 4: i←i+1;
-Bước 5: Nếu i<=n thì quay lại bước 3
-Bước 6: Xuất t và dem
-Bước 7: Kết thúc
Câu 2:
b) uses crt;
var a:array[1..100]of integer;
i,n,t,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
t:=t+a[i];
inc(dem);
end;
writeln('So so chan la: ',dem);
writeln('Tong cac so chan la: ',t);
readln;
end.
uses crt;
var n:string;
i,ln,nn,t,s,x,y:integer;
begin
clrscr;
readln(n);
writeln(length(n));
ln:=0;
nn:=9;
for i:=1 to length(n) do
begin
val(n[i],x,y);
if ln<x then ln:=x;
if nn>x then nn:=x;
end;
writeln(ln);
writeln(nn);
t:=0;
s:=1;
for i:=1 to length(n) do
begin
val(n[i],x,y);
t:=t+x;
s:=s*x;
end;
writeln(t);
writeln(s);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,dem=0,s=0;
cin >> n;
for (long long i=1;i<=n;i+=2){
dem++;
s+=i;
}
cout << "tu 0 den n co: " << dem << " so le" << endl;
cout << "tong cac so le do la: " << s;
return 0;
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,dem=0,s=0;
cin >> n;
for (long long i=1;i<=n;i+=2){
dem++;
s+=i;
}
cout << "tu 0 den n co: " << dem << " so le" << endl;
cout << "tong cac so le do la: " << s;
return 0;
}
var i,n,d:integer;
s:longint;
begin
write('n = ');readln(n);
for i:=1 to n do
if i mod 2 <> 0 then
begin
d:=d+1;
s:=s+i;
end;
writeln('co ',d,' so le');
write('tong cac so le la ',s);
readln;
end.
uses crt;var n: longint; chrn: string; valn,sum,max,i,preperror: byte;begin write('Nhap so can kiem tra: '); readln(n); str(n,chrn); for i:=1 to length(chrn) do begin val(chrn[i],valn,preperror); sum:=sum+valn; if max<valn then max:=valn; valn:=0 end; writeln('Ket qua: '); writeln(length(chrn)); writeln(sum); write(max); readln;end.uses crt;var n: longint; chrn: string; valn,sum,max,i,preperror: byte;begin write('Nhap so can kiem tra: '); readln(n); str(n,chrn); for i:=1 to length(chrn) do begin val(chrn[i],valn,preperror); sum:=sum+valn; if max<valn then max:=valn; valn:=0 end; writeln('Ket qua: '); writeln(length(chrn)); writeln(sum); write(max); readln;end.
Program HOC24;
var N:longint;
max,tg,t,d: integer;
Begin
write('Nhap N : '); readln(N);
max:=0;
while n<>0 do
begin
tg:=n mod 10;
d:=d+1;
t:=t+tg;
if tg>max then max:=tg;
n:=n div 10;
end;
writeln('So nguyen N co ',d,' chu so');
writeln('Tong cac chu so cua N la : ',t);
write('Chu so lon nhat cua N la :',max);
readln
end.
program TinhTongGiaiThua;
uses crt;
var
n, num, sum, digitCount: integer;
function GiaiThua(x: integer): integer;
var
i, fact: integer;
begin
fact := 1;
for i := 1 to x do
begin
fact := fact * i;
end;
GiaiThua := fact;
end;
begin
clrscr;
write('Nhap so n: ');
readln(n);
sum := 0;
digitCount := 0;
while n > 0 do
begin
num := n mod 10;
sum := sum + GiaiThua(num);
digitCount := digitCount + 1;
n := n div 10;
end;
writeln('Tong giai thua cac chu so cua n la: ', sum);
writeln('Tong so chu so cua n la: ', digitCount);
readln;
end.