Viết chương trình nhập vào dãy số. Sau đó đếm xem có bao nhiêu số chia hết cho 2,3 . rồi sắp xếp theo thứ tự giảm đần. Giúp e vs cần gấp lắm
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.
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;
}
Program HOC24;
var i,n,d: integer;
a: array[1..1000] of integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,': '); readln(a[i]);
end;
d:=0;
for i:=1 to n do if a[i] mod 5<>0 then d:=d+1;
write('Co ',d,' so khong chia het cho 5');
readln
end.
1)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] > a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep tang dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
2)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] < a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep giam dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
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;
long long a[1000],n,i,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (i%2!=0) t+=a[i]*a[i];
cout<<t<<endl;
for (i=1;i<=n; i++)
if (a[i]<0) cout<<a[i]<<" ";
cout<<endl;
sort(a+1,a+n+1);
for (i=n; i>=1; i--)
cout<<a[i]<<" ";
return 0;
}
Program Tin_hoc;
uses crt;
var n,i,dem:integer;
a:array[1..10000] of integer;
Begin
clrscr;
readln(n);
dem:=0;
for i:= 1 to n do
Begin
readln(a[i]);
if a[i] mod 2 = 0 then inc(dem);
end;
writeln('Day so co ',dem,' so chan');
readln;
end.
uses crt;
Var i,n,dem:integer;
a: array[1..1000] of integer;
Begin
clrscr;
Write('Nhap do dai cua day: ');readln(n);
dem:=0;
for i:= 1 to n do
Begin
write('So thu ',i,' = ');
readln(a[i]);
if a[i] mod 2 = 0 then inc(dem);
end;
Writeln('Day so co ',dem,' so chan');
readln;
End.
uses crt;
Var i,n,dem:integer;
a: array[1..1000] of integer;
Begin
clrscr;
Write('Nhap do dai cua day: ');readln(n);
dem:=0;
for i:= 1 to n do
Begin
write('So thu ',i,' = ');
readln(a[i]);
if a[i] mod 2 = 0 then inc(dem);
end;
Writeln('Day so co ',dem,' so chan');
readln;
End.
uses crt;
Var i,n,dem:integer;
a: array[1..1000] of integer;
Begin
clrscr;
Write('Nhap do dai cua day: ');readln(n);
dem:=0;
for i:= 1 to n do
Begin
write('So thu ',i,' = ');
readln(a[i]);
if a[i] mod 2 = 0 then inc(dem);
end;
Writeln('Day so co ',dem,' so chan');
readln;
End.
uses crt;
var i,n,dem:longint;a:array[1..1000]of longint;
begin
clrscr;
write('nhap so phan tu cua day:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu thu',i,'=');readln(a[i]);
end;
for i:=1 to n do if(a[i] mod 2=0)then inc(dem);
writeln('co tat ca:',dem,'so chan');
readln;
end.
Var a:array:[1..1000] of integer;
i,n,t,d:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
if (a[i] mod 2 = 0) and (a[i] mod 3 = 0) then
d:=d+1;
End;
Writeln('Co ',d,' so chia het cho 2 va 3');
For i:=1 to n do
If a[i] < a[i+1] then
begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
end;
write('Day sau khi sap xep la: ');
for i:=1 to n do
Write(a[i]:8);
Readln
End.