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
Câu 1: viết chương trình nhập vào N số tự nhiên đầu tiên,đếm xem có bao nhiêu số là số chẵn Câu 2: Viết chương trình nhập vào N số tự nhiên tính tổng các số chia hết cho 3 Em cần gấp lắm ạ:(
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;
}
Viết chương trình nhập vào dãy N số nguyên, đếm xem có bao nhiêu số ko chia hết cho 5(N nhập đc vào từ bàn phím ) GIÚP MIK VS MN MAI MIK THÌ TIN RỒI
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.Viết chương trình nhập vào một dãy số gồm n phần tử.Sắp xếp dãy số theo thứ tự tăng dần sau đó in ra màn hình dãy số đã sắp xếp. 2.Viết chương trình nhập vào một dãy số gồm n phần tử. Sắp xếp dãy số theo thứ tự giảm dần sau đó in ra màn hình dãy số đã sắp xếp.(cứu mk với mai thi r ạ🥲
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.
MÌNH CẦN GẤP Ạ, MAI THI RỒI :(( 1. Viết chương trình tính tổng và tích các số chia hết cho 3 trong dãy số N. 2. Viết chương trình đếm xem trong dãy số N có bao nhiêu số chẵn và tính tổng các số chẵn đó. 3. Viết chương trình đếm có bao nhiêu số chẵn hoặc lẻ trong dãy số N rồi tính tổng và tích của các số chẵn và lẽ đó. Mong mọi người giúp mình :((
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.
Câu 3:
uses crt;
var a:array[1..100]of integer;
i,n,dem1,dem2,t1,t2,s1,s2:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem1:=0;
dem2:=0;
t1:=0;
t2:=0;
s1:=1;
s2:=1;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
inc(dem1);
t1:=t1+a[i];
s1:=s1*a[i];
end
else begin
inc(dem2);
t2:=t2+a[i];
s2:=s2*a[i];
end;
end;
if dem1=0 then writeln('Khong co so chan trong day')
else begin
writeln('So so chan la: ',dem1);
writeln('Tong cac so chan la: ',t1);
writeln('Tich cac so chan la: ',s1);
end;
if dem2=0 then writeln('Khong co so le trong day')
else begin
writeln('So so le la: ',dem2);
writeln('Tong cac so le la: ',t2);
writeln('Tich cac so le la: ',s2);
end;
readln;
end.
Giúp mk gấp vs Viết chương trình nhập vào số nguyên n 1. đếm và tổng bình phương các số ở vị trí lẻ 2. in ra các số không âm 3. sắp xếp n số trên theo thứ tự giảm dần
#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;
}
viết chương trình nhập 1 dãy số .sau đó đếm xem có bau nhiêu số chẵn.
help mình vs free pascal mình cần gấp!!!!
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.
viết chương trình nhập 1 dãy số .sau đó đếm xem có bau nhiêu số chẵn.
help mình vs free pascal mình cần gấp!!!!
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.
viết chương trình nhập 1 dãy số .sau đó đếm xem có bau nhiêu số chẵn.
help mình vs free pascal mình cần gấp!!!!
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.
viết chương trình nhập 1 dãy số .sau đó đếm xem có bau nhiêu số chẵn.
help mình vs free pascal mình cần gấp!!!!
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.