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:
Program HOC24;
var i,p: integer;
t: longint;
begin
write('Nhap P: '); readln(p);
t:=0;
for i:=1 to p do if i mod 2<>0 then t:=t+i;
write('Tong cac so le la: ',t);
readln
end.
Program HOC24;
var i,n: integer;
S,P: longint;
begin
write('Nhap n: '); readln(n);
{..............................................}
readln
end.
-----------------------------------------------------------
Bạn điền vào {........................} theo từng bài nhé
a) S:=0;
for i:=1 to N do if i mod 2=1 then s:=s+i;
write('S= ',s);
b)
S:=0;
for i:=1 to N do if i mod 2=0 then s:=s+i;
write('S= ',s);
c) P:=1;
for i:=1 to N do if i mod 2=0 then p:=p*i;
write('P= ',p);
d)
P:=1;
for i:=1 to N do if i mod 2=1 then p:=p*i;
write('P= ',p);
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,A[100],dem,t;
cin>>n;
for (int i=1; i<=n; i++)
cin>>A[i];
dem=0; t=0;
for (int i=1; i<=n; i++)
if (A[i]%2==0) dem++;
else t+=A[i];
cout<<dem<<endl;
cout<<t;
return 0;
}
uses crt;
var m,n,t,i:integer;
begin
clrscr;
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
t:=0;
for i:=m to n do
if i mod 2=0 then t:=t+i;
writeln('Tong cac so chan tu ',m,' den ',n,' la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,t;
int main()
{
cin>>n;
if (n%2==0)
{
t=0;
for (i=1; i<=n; i++) if (i%2==0) t+=i;
}
else
{
t=0;
for (i=1; i<=n; i++) if (i%2!=0) t+=i;
}
cout<<t;
return 0;
}
tk
uses crt;
var m,n,t,i:integer;
begin
clrscr;
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
t:=0;
for i:=m to n do
if i mod 2=0 then t:=t+i;
writeln('Tong cac so chan tu ',m,' den ',n,' la: ',t);
readln;
end.
uses crt;
var n,i,t,dem:integer;
begin
clrscr;
readln(n);
if n mod 2=0 then
begin
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+i;
writeln(t);
end
else
begin
t:=0;
dem:=0;
for i:=1 to n do
if i mod 2=1 then
begin
t:=t+i;
dem:=dem+1;
end;
writeln(t/dem:4:2);
end;
readln;
end.
{PROGRAM Bai_tap1;
USES crt;
VAR n, i, C, L:Bytbe;
BEGIN
clrscr;
Write('Nhap n:');Readln(n);
C:=0;L:=0;
For i:=1 to n do
If i mod 2=0 then C:=C+i else L:=L+i;
writeln('Tong cac so chan la:',C);
writeln ('Tong cac so le la:',L);
Readln;
end.
}
uses crt;
var m,n,t1,t2,i:integer;
begin
clrscr;
repeat
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
until m<=n;
t1:=0;
t2:=0;
for i:=m to n do
begin
if i mod 2=0 then t1:=t1+i
else t2:=t2+i;
end;
writeln('Tong cac so chan tu ',m,' den ',n,' la: ',t1);
writeln('Tong cac so le tu ',m,' den ',n,' la: ',t2);
readln;
end.