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.
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.
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.
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.
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;
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.
program TinhTich;
var
tich: real;
i: integer;
begin
tich := 1;
for i := 1 to 7 do
begin
case i of
1: tich := tich * 1,2;
2: tich := tich * 1;
3: tich := tich * 4;
4: tich := tich * 1.6;
5: tich := tich * 108;
6: tich := tich * 110;
7: tich := tich * (1/12) * (1/14);
end;
end;
writeln('Tich cua day so la: ', tich:0:2);
end.