nhập n (n>0) nếu n là số chẵn thì tính s=2+4+6+n
nếu số lẻ thì tính S=1+3+5+7+n
cái này giải bằng pascal ai biết giúp mình, mình tick cho
Mọi người giúp mình câu này với ạ :
Tính tổng : S= 1-2-3+4+5-6-7+8+9-10-11+12+...+n
Viết chương trình pascal nhập vào một số n tính tổng từ 1 đến n theo 2 cách
MỌI NGƯỜI ƠI GIÚP EM GIẢI BÀI NÀY VỚI Ạ EM CẢM ƠN !!!
(bài này là viết chương trình nha mọi người)
ĐỀ BÀI
Nhập số N là số nguyên dương từ bàn phím và thực hiện:
+ Nếu N là số chẵn thì S = 2 x 4 x 6 x .... x N
+ Nếu N là số lẻ thì S = 1 x 3 x 5 x .... x N
(mọi người giải gấp giúp em ạ tại ngày mai em nộp bài cho cô rồi ạ
#include <bits/stdc++.h>
using namespace std;
long long n,i,s;
int main()
{
cin>>n;
if (n%2==0)
{
s=1;
for (i=1; i<=n; i++)
if (i%2==0) s=s*i;
cout<<s;
}
else
{
s=1;
for (i=1; i<=n; i++)
if (i%2==1) s=s*i;
cout<<s;
}
return 0;
}
Viết ctrinh dưới đây bằng ngôn ngữ lập trình pascal? a)Tính tổng các số lẻ trong phạm vi từ 1 đến N(S=1+3+5+7...+N) b)Tính tổng các số chẵn trong phạm vi từ 1 đến N(S=2+4+6+8...+N c)Tính tích các số chẵn trong phạm vi từ 1 đến N(P=2.4.6...N) d)Tính tích các số lẻ trong phạm vi từ 1 đến N(P=1.3.5...N)
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);
giải câu này cho mk vs\(Nhập từ bàn phím số nguyên dương N gồm 4 chữ số. Nếu N là số chẵn thì đếm chữ số 0 có trong số N còn nếu N là số lẻ thì tính tổng bình phương của các chữ số trong số N.\)
uses crt;
var n,d,dem,i,x,y,t:integer;
st:string;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (1000<=n) and (n<=9999);
if n mod 2=0 then
begin
str(n,st);
d:=length(st);
dem:=0;
for i:=1 to d do
begin
val(st[i],x,y);
if x=0 then inc(em);
end;
writeln('So chu so 0 co trong so ',n,' la: ',dem);
end
else begin
str(n,st);
t:=0;
d:=length(st);
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+sqr(x);
end;
writeln('Tong binh phuong cac chu so trong so ',n,' la: ',t);
end;
readln;
end.
uses crt;
var n,d,dem,i,x,y,t:integer;
st:string;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (1000<=n) and (n<=9999);
if n mod 2=0 then
begin
str(n,st);
d:=length(st);
dem:=0;
for i:=1 to d do
begin
val(st[i],x,y);
if x=0 then inc(em);
end;
writeln('So chu so 0 co trong so ',n,' la: ',dem);
end
else begin
str(n,st);
t:=0;
d:=length(st);
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+sqr(x);
end;
writeln('Tong binh phuong cac chu so trong so ',n,' la: ',t);
end;
readln;
end.
Lập trình bài toán bằng Python tính S với nhập n là số lẻ và n>99 tính S=1/3+1/5+1/7+…+1/n S=0,for n (3,n+1,2) S=S+1/n
viết chương trình nhập số n, nếu n là số chẵn thì tính tổng các số chẵn từ 1 tới n, nếu n là số lẻ thì tính trung bình cộng các số lẻ từ 1 tới n.
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;
}
Viết chương trình nhập số n, nếu n là số chẵn thì tính tổng các số chẵn từ 1 tới n, nếu n là số lẻ thì tính trung bình cộng các số lẻ từ 1 tới n
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.
Viết chương trình :
a) nhập các số x,y,n,z:
b)kiểm tra xem các số x,y,n,z là số chẵn hay số lẻ.
c)tính S=1+4+7+...+n
d)tính A=\(\frac{x}{x+y}+\frac{x^2}{\left(x+y\right)^2}+\frac{x^3}{\left(x+y\right)^3}+...+\frac{x^n}{\left(x+y\right)^n}\)
Giúp mình nhé cần gấp!
Ai đúng mik t**k cho!!!
S=1+4+7+..+n
Tổng S có số số hạng là \(\frac{\left(n-1\right)}{3}+1=\frac{n+2}{3}\)
Tổng S có giá trị là
\(S=\frac{\left(n+1\right)}{2}.\frac{n+2}{3}=\frac{\left(n+1\right)\left(n+2\right)}{6}\)
1. Viết chương trình Pascal tính tổng các số chia hết cho 3 từ 1 đến 100 Kết quả tổng này là số chẵn hay lẻ? 2. Viết chương trình Pascal nhập vào 1 mảng số nguyên A gồm có N số (N< 100). Có bao nhiêu số chẵn trong mảng A.
Bài 2:
uses crt;
var x,i,n,dem:integer;
begin
clrscr;
readln(n);
dem:=0;
for i:=1 to n do
begin
readln(x);
if x mod 2=0 then inc(dem);
end;
writeln(dem);
readln;
end.