Viết chương trình nhập vào bàn phím 2 số nguyên dương tìm ước chung lớn nhất MN sau đó in kết quả ra màn hình yêu cầu sử dụng hàm
Bài 1: Viết chương trình pascal thực hiện các yêu cầu sau: a) Nhập từ bàn phím 1 số nguyên n b) In ra màn hình kết quả tổng các số nguyên từ 1 đến n (sử dụng câu lệnh lặp while...do) Bài 2: Viết chương trình pascal thực hiện câc yêu cầu sau: a) Nhập từ bàn phím 1 số nguyên dương n b) In ra màn hình kết quả tổng các số lẻ từ 1 đến n (sử dụng câu lệnh lặp while...do giúp mình với mình đang cần gấp rất gấp luôn
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
inc(i);
end;
writeln('Tong cac so trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Bài 2:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+2;
end;
writeln('Tong cac so le trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Viết chương trình nhập vào từ bàn phím một số nguyên dương n, in ra màn hình các số lẻ nhỏ hơn hoặc bằng số nguyên dương n. Chương trình yêu cầu nhập lại nếu n <=0. (Sử dụng câu lệnh While … do)
program Le_Nho_Hon_Hoac_Bang_n;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
while n <= 0 do
begin
writeln('So ban nhap khong hop le. Xin vui long nhap lai: ');
readln(n);
end;
clrscr;
writeln('Cac so le nho hon hoac bang ', n, ' la:');
i := 1;
while i <= n do
begin
if i mod 2 <> 0 then
writeln(i);
i := i + 1;
end;
readln;
end.
Câu 1. Viết chương trình thực hiện yêu cầu sau: a, Sử dụng mảng để nhập từ bàn phím các phân tử của 1 dãy số có kiểu số nguyên? Biết độ dài của dãy số được nhập từ bàn phím . b, In ra màn hình các số vừa nhập của dãy số đó. c, In ra màn hình số lớn nhất trong dãy số. Mn giúp mik với mik cần gấp.mik c.ơn
Var a:array:[1..1000] of integer;
i,n,max:integer;
Begin
Write('Nhap so luong phan tu n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
End;
Write('Cac diem vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
max:=a[1];
For i:=2 to n do
if a[i] > max then max:=a[i];
write('So lon nhat la ',max);
Readln
End.
Cho dãy số 2;5;8;11;... Viết Chương trình yêu cầu nhập số nguyên N từ bàn phím tính tích E sau đó in kết quả ra màn hình E=2.5.8.11....n
Var i,n:integer;
E:real;
Begin
Write('Nhap n = ');readln(n);
E:=1;
For i:=2 to n do
Begin
E:=E*i;
i:=i+2;
End;
Write('E = ',E:15:0);
Readln;
End.
Viết chương trình Pascal thực hiện yêu cầu sau:
a)Sử dụng biến mạng , nhập vào dãy số nguyên từ bàn phím ,in ra màn hình dãy số đó
b)In ra màn hình tổng của dãy số đó
sử dụng biến mảng viết chương trình nhập vào N số nguyên từ bàn phím .sau đó in ra màn hình giá trị lớn nhất và nhỏ nhất của dãy số
giúp mik với
Program HOC24;
var min,max,i,n: integer;
a: array[1..1000] of integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1]; min:=a[1];
for i:=2 to n do
begin
if a[i]> max then max:=a[i];
if a[i]<min then min:=a[i];
end;
writeln('Gia tri lon nhat la: ',max);
write('Gia tri nho nhat la: ',min);
readln
end.
Câu 1 viết chương trình tính giá trị biểu thức với x,y là các số nguyên dc nhập từ bàn phím. In kết quả ra màn hình Caau2 viết chương trình vào 3 số nguyên a,b,c.In ra màn hình số lớn nhất trong 3 số đó
Câu 2:
Program nii;
Uses crt;
Var a,b,c,A:integer;
Begin
Write ('nhap a');
Readln (a);
Write ('nhap b');
Readln (b);
Write ('nhap c');
Readln (c);
A:=a;
If A<b then A:=b;
If A<c then A:=c;
Write ('Ket qua',A);
Readln;
End.
Câu 1
Program ntg;
Uses crt;
Var A,x,y:integer;
Begin
Write ('nhap x');
Readln (x);
Write ('nhap y');
Readln ('y');
A:=x+y;
Write ('Ket qua',A);
Readln;
End.
Câu 2:
uses crt;
var a,b,c,max:integer;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
write('Nhap c='); readln(c);
max:=a;
if max<b then max:=b;
if max<c then max:=c;
writeln('So lon nhat trong 3 so la: ',max);
readln;
end.
sử dụng biến mảng Viết chương trình nhập vào một dãy số gồm n số nguyên từ bàn phím in ra màn hình giá trị lớn nhất của dãy số đó
uses crt;
var a:array[1..100]of integer;
i,n,max:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln(max);
readln;
end.
Câu2: viết chương trình thực hiện yêu cầu sau . a, Sử dụng biến mảng để nhập từ bàn phím điểm trung bình (ĐTB) của 50 bạn học sinh trong lớp. b,In rs màn hình (ĐTB) của học sinh . c,In ra màn hình số lớn nhất trong dãy số . Mn giúp mik vs mik cần gấp.mik c.ơn
Var a:array:[1..50] of real;
i,max:integer;
Begin
For i:=1 to 50 do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
Write('Cac diem vua nhap la: ');
For i:=1 to 50 do
Write(a[i]:10:2);
Writeln;
max:=a[1];
For i:=2 to 50 do
if a[i]>max then max:=a[i];
Write('Diem trung binh lon nhat la ',max:10:2);
Readln
End.
Var a:array:[1..50] of real;
i:integer;
max:real;
Begin
For i:=1 to 50 do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
End;
Write('Cac diem vua nhap la: ');
For i:=1 to 50 do
Write(a[i]:10:2);
writeln;
max:=a[1];
For i:=2 to 50 do
if a[i] > max then max:=a[i];
write('Diem lon nhat la ',max:10:2);
Readln
End.