Chương trình nhập vào 2 số x và y với x,y là số nguyên được nhập từ bàn phím tính và xuất ra màn hình tổng hai số x,y
uses crt;
var x,y:integer;
begin
clrscr;
write('Nhap x='); readln(x);
write('Nhap y='); readln(y);
if x>y then writeln(x-y)
else writeln(x+y);
readln;
end.
uses crt;
var x,y:integer;
begin
clrscr;
write('Nhap x='); readln(x);
write('Nhap y='); readln(y);
if x>y then writeln(x-y)
else writeln(x+y);
readln;
end.
1. Thực hành
Bài 1: Viết chương trình nhập số nguyên n từ bàn phím. Kiểm tra và in ra màn hình số n có hợp lệ hay không với điều kiện n là số nguyên dương chẵn.
Bài 2: Viết chương trình Pascal nhập các số nguyên x và y từ bàn phím, in giá trị của x và y ra màn hình. Sau đó hoán đổi các giá trị của x và y rồi in lại ra màn hình giá trị của x và y.
• Ví dụ cho x:=5; y:=7.Hoán đổi để x:=7; y:=5.Cho 1 biến trung gian là z, ta hoán đổi x, y cho nhau bằng cách:
• z:=y { gán giá trị số 7 vào biến nhớ z }
• y:=x { gán giá trị số 5 vào biến nhớ y }
• x:=z { gán giá trị số 7 vào biến nhớ x }
Bài 3: Viết chương trình nhập vào ba số nguyên a, b và c từ bàn phím. Tính và in ra màn hình:
X= a + b + c
Y= (a + b)2 / c.
Chạy lại chương trình và nhập giá trị cho a là 10.5, quan sát kết quả và nêu nhận xét.
Bài 2:
#include <bits/stdc++.h>
using namespace std;
long long x,y;
int main()
{
cin >>x>>y;
cout<<x<<" "<<y;
swap(x,y);
cout<<x<<" "<<y;
return 0;
}
Bài 1: Viết chương trình Pascal nhập số từ bàn phím. Xuất ra màn hình:
+ Tính n!
+ Nhập số x từ bàn phím.Tính nx
Bài 2: Viết chương trình Pascal nhập số n từ bàn phím. Xuất ra màn hình
+ Dòng 1: Các ước của n
+ Dòng 2: Nếu n là số lẻ thì xuất ra màn hình các số nguyên tố từ 2 đến n
+ Dòng 3: Nếu n là chẵn thì xuất ra màn hình các số hoàn hảo từ 1 đến n
+ Dòng 4: Tổng các ước của n
( 2 bài khác nhau mọi người làm riêng ra giúp mình ạaaaaaa)
Cho biểu thức y = 5 - 2x. Em hãy viết chương trình Pascal tính và in ra màn hình giá trị y. Với x, y là hai biến của chương trình có kiểu dữ liệu là số nguyên, giá trị của x đươc nhập vào từ bàn phím.
giúp em với mng, cảm ơn mng rất nhiều ạ<3
Viết trương trình Pescal, tính tổng các số nguyên tố nằm trong khoảng từ X đến Y rồi in ra màn hình .Với X,Y là các số tự nhiên được nhập từ bàn phím ra 2<x<y
program TinhTongSoNguyenTo;
var
X, Y, i, j, dem, tong: integer;
begin
write('Nhap X: ');
readln(X);
write('Nhap Y: ');
readln(Y);
tong := 0;
for i := X to Y do
begin
dem := 0;
for j := 2 to i div 2 do
if i mod j = 0 then
begin
dem := dem + 1;
break;
end;
if dem = 0 then
tong := tong + i;
end;
writeln('Tong cac so nguyen to tu ', X, ' den ', Y, ' la: ', tong);
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.
viết chương trình in ra màn hình số lớn trong 2 số x,y được nhập vào từ bàn phím
uses crt;
var x,y:integer;
begin
clrscr;
readln(x,y);
if x>y then write(x)
else write(y);
readln;
end.
Câu 1: Viết chương trình tính và in ra màn hình diện tích và chu vi của hình chữ nhật, với chiều dài và chiều rộng là số nguyên nhập từ bàn phím.
Câu 2: Viết chương trình nhập các số nguyên x và y, in giá trị của x và y ra màn hình. Sau đó hoán đổi các giá trị của x và y rồi in ra màn hình giá trị của x và y.
Lưu ý: Câu lệnh hoán đổi 2 biến x và y: Z:=x;
X:=y;
Y:=z;