Viết chương trình tính tích sau t = 1,2 x 1 x 4 x 1,6 x 108 x 110 x 1/12 x 1/14 sử dụng câu lệnh for do help me
Câu 14 (2,0 điểm): Trong các câu lệnh lặp trong Pascal sau đây đúng hay sai. Vì
sao?
a. While i<5 do i=i+1;
b. While 3=3 do i:=i+1;
c. While x<3 do x:=x+1;
d. For i:=2.5 to 10 do x:=x+1;
Cho biết giá trị của biến S và n sau khi thực hiện đoạn chương trình trên
Viết chương trình tìm số lớn nhất của n số nguyên X 1 x 2 x 3 x n các số x 1 x 2 x 3 x n được nhập vào từ bàn phím sử dụng lệnh while do
program tim_max;
uses crt;
var i,n,max:integer;
x:array[1..100]of byte;
begin
clrscr;
write('nhap so n:');readln(n);
i:=1;
while i<=n do
begin
write('x[',i,']=');readln(x[i]);
i:=i+1;
end;
max:=x[1];i:=1;
while i<=n do
begin
if max<x[i] then max:=x[i];
i:=i+1;
end;
write('so lon nhat la:',max);
readln;
end.
(Viết chương trình Pascal sử dụng câu lệnh while...do)
1. Viết chương trình nhập vào 1 dãy gồm n số nguyên và tính tổng, trung bình của dãy vừa nhập.
2. Viết chương trình nhập 1 số nguyên x, kiểm tra số vừa nhập có phải số nguyên tố hay không.
Bài 1
Var s,i:integer;
tb:real;
Begin
Write('Nhap n = ');readln(n);
i:=1;
s:=0;
While i<=n do
Begin
s:=s+i;
i:=i+1;
End;
tb:=s/n;
Writeln('Tong la ',s);
Write('Trung binh la ',tb:10:2);
Readln;
End.
Bài 2
Var i,n,souoc:integer;
Begin
Write('Nhap n = ');readln(n);
i:=1;
While i <= n do
Begin
i:=i + 1;
If n mod i = 0 then souoc:=souoc + 1;
End;
If souoc = 1 then write(n,' la so nguyen to')
Else write(n,' khong la so nguyen to');
Readln;
End.
4. Viết các chương trình của một số bài toán sử dụng câu lệnh lặp While . . Do. c) P = 3. 5. 7 … X, với X là số lẻ được nhập từ bàn phím..
Program HOC24;
var p: longint;
i,x: integer;
Begin
write('Nhap X: '); readln(X);
p:=1;
for i:=3 to x do if i mod 2=1 then p:=p*i;
write('P = ',p);
readln
end.
Bài toán tính tổng : S=1+1/2+1/3+...+1/100
a.Nêu thuật toán và viết chương trình sử dụng câu lệnh For...to...do
b.Nêu thuật toán và viết chương trình sử dụng câu lệnh While...do
a: uses crt;
var i,n:integer;
s:real;
begin
clrscr;
s:=0;
for i:=1 to 100 do s:=s+1/i;
writeln(s:4:2);
readln;
end.
b:
uses crt;
var i,n:integer;
s:real;
begin
clrscr;
s:=0;
i:=0;
while i<=100 do
begin
inc(i);
s:=s+1/i;
end;
writeln(s:4:2);
readln;
end.
Viết chương trình sử dụng câu lệnh lặp tính tổng các số dương trong dãy x1,x2,x3...xn được nhập từ bàn phím.
Cần gấp ạ,,,,help me Pls TvT
Trong đoạn lệnh sau đây, chương trình đã thực hiện bao nhiêu vòng lặp?
x:=0; For i:=1 to 10 do x:=x+3;
Cho các câu lệnh sau chỉ ra câu lệnh đúng:
A: for i:=1 to 10; do x:=x+1;
B: for i:=1 to 10 do x:=x+1;
C: for i:=10 to 1 do x:=x+1;
D: for i=10 to 1 do x:=x+1;
Cho các câu lệnh sau chỉ ra câu lệnh đúng:
A: for i:=1 to 10; do x:=x+1;
B: for i:=1 to 10 do x:=x+1;
C: for i:=10 to 1 do x:=x+1;
D: for i=10 to 1 do x:=x+1;
Cho các câu lệnh sau chỉ ra câu lệnh đúng:
A: for i:=1 to 10; do x:=x+1;
B: for i:=1 to 10 do x:=x+1;
C: for i:=10 to 1 do x:=x+1;
D: for i=10 to 1 do x:=x+1;
Bài 1: Viết chương trình cho bài toán sau (sử dụng câu lệnh For...do và While...do)
a) 1+2+3+4+5+6+7+8+9
b) 2+4+6+8+10+12+14
c) 3+5+7+9+11+13+15
lệnh for...to...do:
a)program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
for i:=1 to 9 do s:=s+i;
write(s);
readln;
end.
b)
program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
for i:=1 to 14 do
begin
if i mod 2=0 then
s:=s+i;
end;
write(s);
readln;
end.
c)
program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
for i:=1 to 15 do
begin
if i mod 2=1 then
s:=s+i;
end;
write(s);
readln;
end.
lệnh while...do
a)program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
i:=1;
while i<=9 do
begin
s:=s+i;
i:=i+1;
end;
write(s);
readln;
end.
b)program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
i:=1;
while i<=14 do
begin
if i mod 2=0 then
s:=s+i
else i:=i+1;
end;
write(s);
readln;
end.
c)
program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
i:=1;
while i<=15 do
begin
if i mod 2=1 then
s:=s+i
else i:=i+1;
end;
write(s);
readln;
end.