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:
Input: Số n
Output: Kiểm tra xem n có chia hết cho 5 ko
Mô tả thuật toán:
Bước 1: Nhập n
Bước 2: Nếu n chia hết cho 5 thì xuất ra có
không thì không
Bước 3: Kết thúc
Viết ct:
uses crt;
var n:integer;
begin
clrscr;
readln(n);
if n mod 5=0 then write('yes')
else write('no');
readln;
end.
Var a,b,c,d:integer;
Begin
Writeln('Cac so can tim la');
For a:=1 to 9 do
For b:=0 to 9 do
For c:=0 to 9 do
For d:=0 to 9 do
If a + b + c + d = 20 then
writeln(a,b,c,d);
readln;
End.
1:
#include <bits/stdc++.h>
using namespace std;
long long dem,i,n,x;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0) dem++;
}
cout<<dem;
return 0;
}
Câu 2:
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%3==0) t+=x;
}
cout<<t;
return 0;
}
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.
#include <bits/stdc++.h>
using namespace std;
int main()
{
string st;
int d,i,dem=0;
getline(cin,st);
d=st.length();
for (int i=0; i<d; i++)
if (st[i]=' ') dem++;
cout<<dem+1;
return 0;
}
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.
uses crt;
var n,i,d,dem,kt,t,kt1,t1,t2,t3,max,min,x,j:integer;
a,b:array[1..100]of integer;
st:string;
begin
clrscr;
write('Nhap n='); readln(n);
str(n,st);
d:=length(st);
for i:=1 to d do
val(st[i],a[i],x);
dem:=1;
b[1]:=a[1];
for i:=1 to d do
begin
kt:=0;
for j:=1 to dem do
if a[i]=b[j] then kt:=1;
if kt=0 then
begin
inc(dem);
b[dem]:=a[i];
end;
end;
writeln('Cac chu so cua ',n,' la: ');
for i:=1 to dem do
write(b[i]:4);
writeln;
t:=0;
for i:=1 to d do
t:=t+a[i];
writeln('Tong cac chu so cua ',n,' la: ',t);
kt1:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then
begin
kt1:=1;
break;
end;
if (kt1=0) and (t>1) then writeln(t,' la so nguyen to')
else writeln(t,' khong la so nguyen to');
writeln('Cac chu so o vi tri le cua ',n,' la: ');
t1:=0;
for i:=1 to d do
if i mod 2=1 then
begin
write(a[i]:4);
t1:=t1+a[i];
end;
writeln;
writeln('Tong cac chu so o vi tri le la: ',t1);
if trunc(sqrt(t1))=sqrt(t1) then writeln(t1,' la so chinh phuong')
else writeln(t1,' khong la so chinh phuong');
writeln('Cac chu so o vi tri chan cua ',n,' la: ');
t2:=0;
for i:=1 to d do
if i mod 2=0 then
begin
write(a[i]:4);
t2:=t2+a[i];
end;
writeln('Tong cac chu so o vi tri chan la: ',t2);
t3:=0;
for i:=1 to t2 do
if t2 mod i=0 then t3:=t3+i;
if (t3=t2) and (t2>0) then writeln(t2,' la so hoan hao')
else writeln(t2,' khong la so hoan hao');
max:=a[1];
min:=a[1];
for i:=1 to d do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('Chu so lon nhat cua ',n,' la: ',max);
writeln('Chu so nho nhat cua ',n,' la: ',min);
writeln('Tong cua chung la: ',max+min);
readln;
end.
uses crt;
var i,t,d,x,y,j:integer;
st:string;
begin
clrscr;
writeln('cac so tu nhien co 4 chu so sao cho so do chia het cho 5 va tong cac chu so la 20 gom cac so:');
for i:=1000 to 9999 do
begin
t:=0;
str(i,st);
d:=length(st);
for j:=1 to d do
begin
val(st[j],x,y);
t:=t+x;
end;
if (i mod 5=0) and (t=20) then write(i:6);
end;
readln;
end.