Synthesis of Pascal exercises has prizes, from easy to difficult

Below is a summary of some basic to complex Pascal exercises that TipsMake.com has gathered, hoping your learning will be a little easier.

Pascal is a fairly old language, in fact it is no longer in common use as before. Compared to modern scripting languages, Pascal is quite lengthy, highly abstract and the code is quite similar to the C programming language. Most C programs can be translated to Pascal but only changed change syntax but not change structure. Which C is one of the very popular programming languages, thus grasping Pascal you will approach C better. It also forces you to always think about data types, which will help new developers learn a great habit when coding.

And because there is not much commercial value, Pascal is used primarily for introductory programming or for Pascal lovers to explore. If you like programming, just learning but not "absorbing" Pascal can try Python.

Below is a summary of some basic to complex Pascal exercises that TipsMake.com has gathered, hoping your learning will be a little easier.

  1. Download Pascal and install Pascal on Windows
  2. Who invented the Pascal programming language?

The Pascal exercise has a prize

  1. Lesson 1: Print even numbers on the screen
  2. Lesson 2: Calculate, print the total, effect, area and trade of 2 numbers
  3. Lesson 3: Check to see if the triangle is balanced and square
  4. Lesson 4: Solving quadratic equations
  5. Lesson 5: Check the parity, element, perfect
  6. Lesson 6: The n-level calculation of a number
  7. Lesson 7: The total number of digits of a number
  8. Lesson 8: Reverse 2 numbers
  9. Lesson 9: Print multiples 3 and 5
  10. Lesson 10: Print the sum of the digits of a number
  11. Lesson 11: Check primes
  12. Lesson 12: Check the perfect number
  13. Lesson 13: Check the main number
  14. Lesson 14: Count vowels and numbers in a string
  15. Lesson 15: Check if 3 numbers are the length of the triangle
  16. Lesson 16: Count numbers by condition and sum
  17. Lesson 17: Find the maximum value of 4 numbers
  18. Lesson 18: See what day of the week is
  19. Lesson 19: Print report card
  20. Lesson 20: Enter 2 real numbers and calculate the calculation as required

Lesson 1: Print even numbers on the screen

Write a program to enter a number of N positive integers and print the screen of even numbers from 0 to N, so that each number takes 4 positions and 1 line has 15 numbers.

The answer:

 uses crt; {khai bao' thu vien crt} var n,i,dem:integer; BEGIN clrscr;{ cau lenh xoa man hinh}; write('Nhap n: ');readln(n); dem:=0; for i:=1 to n do begin if i mod 2=0 then begin write(i:4); dem:=dem+1; end; if dem=15 then begin dem:=0; writeln;{in duoc 15 so thi xuong dong}; end; end; readln END. 

Lesson 2: Calculate, print the total, effect, area and trade of 2 numbers

Enter 2 positive integers a and b. Later:

  1. Calculate and print the screen of the total, effect, trade and the greatest common of the two numbers.
  2. Calculate the sum of the positive divisors of | a + b |

The answer:

 uses crt; var a,b,tg,i,tong:integer; function tinh(x,y:integer):integer; begin tg:= x mod y; if tg=0 then tinh:=y else tinh:=tinh(y,tg); end; BEGIN clrscr; write('Nhap a: ');readln(a); write('Nhap b: ');readln(b); tong:=1; for i:=2 to abs(a+b) do if (abs(a+b) mod i =0) then tong:=tong+i; writeln('Tong 2 so la: ',a+b); writeln('Hieu 2 so la: ',ab); writeln('Tich 2 so la: ',a*b); writeln('Thuong 2 so la: ',a/b:0:4); writeln('UCLN 2 so la: ',tinh(a,b)); writeln('Tong cac uoc cua ',a+b,' la: ',tong); readln END. 

Lesson 3: Check to see if the triangle is balanced and square

Write a program to enter the lengths of the sides of the triangle and then calculate the circumference, area, 3 high paths of the triangle. Check if the triangle is an isosceles triangle or a right triangle.

The answer:

 uses crt; var a,b,c,cv,dt,p:real; BEGIN clrscr; write('Nhap do dai canh a: ');readln(a); write('Nhap do dai canh b: ');readln(b); write('Nhap do dai canh c: ');readln(c); cv:=a+b+c; p:=(a+b+c)/2; dt:=sqrt(p*(pa)*(pb)*(pc)); writeln('Chu vi tam giac la: ',cv:0:4); writeln('Dien tich tam giac la: ',dt:0:4); writeln('Duong cao canh thu 1 la: ',dt*2/a:0:4); writeln('Duong cao canh thu 2 la: ',dt*2/b:0:4); writeln('Duong cao canh thu 3 la: ',dt*2/c:0:4); if (a=b) or (a=c) or(b=c) then writeln('Tam giac can'); if (a*a=b*b+c*c) or (b*b=a*a+c*c) or (c*c=b*b+a*a)then writeln('Tam giac vuong'); readln END. 

Lesson 4: Solving quadratic equations

Write a program to solve quadratic equations.

The answer:

 uses crt; var a,b,c,x1,x2,d:real; BEGIN clrscr; write('Nhap a: ');readln(a); write('Nhap b: ');readln(b); write('Nhap c: ');readln(c); d:=b*b-4*a*c; if d>0 then begin x1:=(-b+sqrt(d))/(2*a); x2:=(-b-sqrt(d))/(2*a); writeln('2 nghiem PT la: ',x1:0:2,' va: ',x2:0:2); end else if d=0 then begin x1:=(-b)/(2*a); writeln('PT co nghiem kep la: ',x1:0:2); end else writeln('PT vo nghiem'); readln END. 

Lesson 5: Check the parity, element, perfect

Enter 1 4-digit integer:

  1. Check parity
  2. Check if it is a prime number
  3. Check if the number is perfect

The answer:

 uses crt; var n,i:integer;ok:boolean; BEGIN clrscr; write('Nhap n: ');readln(n); if n mod 2=0 then writeln('So ',n,' la so chan') else writeln('So ',n,' la so le'); if n 

It is possible to replace the loop 'for i: = 2 to trunc (sqrt (n)) do' by the command while.do.when we do not need to turn ok anymore.

Lesson 6: The n-level calculation of a number

Enter 2 numbers n, a. Calculate the square root of a:

The answer:

 uses crt; var n:integer;a,s:real; BEGIN clrscr; write('Nhap a: ');readln(a); repeat write('Nhap n: ');readln(n); until (n>0); if (n mod 2=0) and (a>=0) then begin s:=exp(1/n*ln(a)); writeln('Ket qua la: ',s:0:4); end else if (n mod 2<>0) then begin s:=exp(1/n*ln(abs(a))); writeln('Ket qua la: ',s:0:4); end else writeln('Khong xac dinh'); readln END. 

Lesson 7: The total number of digits of a number

Enter any 3-digit number and then sum the digits of that number.

The answer:

 uses crt; var a:integer;tong:byte; BEGIN clrscr; write('Nhap 1 so co 3 chu so: ');readln(a); tong:= a mod 10; a:=a div 10; tong:=tong+a mod 10; a:=a div 10; tong:=tong+a mod 10; writeln('Tong cac chu so do la: ',tong); readln END. 

Lesson 8: Reverse 2 numbers

Enter 2 integers a, b, permutate 2 numbers when a> b.

The answer:

 uses crt; var a,b,tg:integer; BEGIN clrscr; write('Nhap a: ');readln(a); write('Nhap b: ');readln(b); if a>b then begin tg:=a; a:=b; b:=tg; end; writeln(a,' ',b); readln END. 

Lesson 9: Print multiples 3 and 5

Enter a positive integer n, print the sum of positive integers from 1 to n which is a multiple of 3 or 5.

The answer:

 uses crt; var n,tong,i:integer; BEGIN clrscr; write('Nhap so nguyen duong n: ');readln(n); tong:=0; for i:=1 to n do if (i mod 3=0) or (i mod 5=0) then tong:=tong+i; writeln('Tong cac so chia het cho 3 hoac 5 tu 0--> ',n,' la: ',tong); readln END. 

Lesson 10: Print the sum of the digits of a number

Enter any n then print the sum of the digits of n.

The answer:

 uses crt; var n,m:longint;tong:byte; BEGIN clrscr; write('Nhap n: ');readln(n); tong:=0;m:=n; while m>0 do begin tong:=tong+m mod 10; m:=m div 10; end; writeln('Tong cac chu so cua ',n,' la: ',tong); readln END 

Lesson 11: Check primes

Enter any number n and check if n is a prime number.

Sample code:

 uses crt; var n,i:integer; BEGIN clrscr; write('Nhap so nguyen duong n: '); readln(n); if n0)) do i:=i+1; if i>trunc(sqrt(n)) then writeln(n,' la so nguyen to') else writeln(n,' khong la so nguyen to'); end; readln END. 

Lesson 12: Check the perfect number

Enter a positive integer n and check if n is the perfect number.

The answer:

The perfect number is the number that has the sum of the divisors (except it) by itself. For example, number 6 has divisors of 1, 2, 3; No. 28, 496 are also perfect numbers.

Sample code:

 uses crt; var n:longint;tong,i:integer; BEGIN clrscr; write('Nhap so nguyen duong n: ');readln(n); tong:=0; for i:=1 to n div 2 do if n mod i=0 then tong:=tong+i; if tong=n then writeln(n,' la so hoan hao') else writeln(n,'khong la so hoan hao'); readln END. 

Lesson 13: Check the main number

Enter any positive integer n and check if n is the main number.

Sample code:

 uses crt; var n:longint; BEGIN clrscr; write('Nhap so nguyen duong n: ');readln(n); if sqrt(n)=trunc(sqrt(n)) then writeln(n,' la so chinh phuong') else writeln(n,' khong la so chinh phuong'); readln END. 

Lesson 14: Count vowels and numbers in a string

Enter a string and check how many vowels there are, how many numbers?

Sample code:

 uses crt; var s:string;dem1,dem2,i:byte; BEGIN clrscr; write('Nhap 1 chuoi: ');readln(s); dem1:=0;dem2:=0; for i:=1 to length(s) do begin if s[i] in ['a','e','i','o','u','y','A','E','I','O','U','Y'] then dem1:=dem1+1; if s[i] in ['0','1','2','3','4','5','6','7','8','9'] then dem2:=dem2+1; end; writeln('Trong chuoi ',s,' co ',dem1,' nguyen am va co ',dem2,' ki tu so'); readln END. 

Lesson 15: Check if 3 numbers are the length of the triangle

Enter any 3 numbers a, b, c. Check if 3 numbers can be the length of 3 sides of a triangle and notify the screen.

Sample code:

 Var a, b, c: Real; BEGIN Writeln ('Nhap do dai 3 canh cua tam giac:'); Write ('a ='); Readln (a); Write ('b ='); Readln (b); Write ('c ='); Readln (c); If (a + b > c) and (b + c > a) and (c + a > b) and (a > 0) and (b > 0) and (c > 0) Then Writeln ('Thoa man: Day la 3 canh cua mot tam giac') Else Writeln ('Khong thoa man!'); Readln; END. 

Lesson 16: Count numbers by condition and sum

Enter any N number. Count numbers greater than 10 and less than 20 and calculate their sum. Then, bring up the screen "So the compared> 10 and

Sample code:

 Var Tong, So: Real; I, N, Dem: Integer; BEGIN Write ('Ban muon nhap bao nhieu so: '); Readln (N); Tong:= 0; Dem:= 0; For I:= 1 To N Do Begin Write ('So = '); Readln (So); If (So > 10) and (So < 20) Then Begin Tong:= Tong + So; Dem:= Dem + 1; End; End; Writeln ('So cac so >10 va 

Lesson 17: Find the maximum value of 4 numbers

Enter 4 numbers a, b, c, d. Find their maximum value and assign that value to the variable Max.

Sample code:

 Var Max, a, b, c, d: Real; BEGIN Writeln ('Nhap gia tri cua 4 so: '); Write ('a = ') ; Readln (a); Write ('b = ') ; Readln (b); Write ('c = ') ; Readln (c); Write ('d = ') ; Readln (d); Max:= a; If Max < b Then Max:= b; If Max < c Then Max:= c; If Max < d Then Max:= d; Writeln ('Gia tri lon nhat la: ', Max); Readln; END. 

Lesson 18: See what day of the week is

Read the date and year, then write down the screen which day of the week.

Sample code:

 Var Thu, Ngay, Thang: Byte; Nam: Integer; BEGIN Write ('Doc Ngay Thang Nam: '); Readln ( Ngay, Thang, Nam ); Nam:= 1900 + (Nam mod 1900); If Thang < 3 Then Begin Thang:= Thang + 12; Nam:= Nam - 1; End; Thu:= Abs (Ngay + Thang * 2 + (Thang + 1) * 3 div 5 + Nam + Nam div 4) mod 7; Case Thu Of 0: Writeln ('Chu Nhat'); 1: Writeln ('Thu Hai'); 2: Writeln ('Thu Ba'); 3: Writeln ('Thu Tu'); 4: Writeln ('Thu Nam'); 5: Writeln ('Thu Sau'); 6: Writeln ('Thu Bay'); End; Readln; END. 

Lesson 19: Print report card

Write a program: Enter your identification number, enter grades, and math. Print to the screen as:

Report card:

Identification number:

Text:

Math scores:

Foreign language scores:

Total score:

You have matriculated: If Total score> = 20.

You do not enroll: If Total score <20.

 Uses Crt; Var SBD: Integer; Van, Toan, Anh, Tongdiem: Real; BEGIN Clrscr; Write ('So bao danh: '); Readln(SBD); Write ('Diem toan: '); Readln(Toan); Write ('Diem ngoai ngu: '); Readln(Anh); Write ('Diem van: '); Readln (Van); Tongdiem:= Toan + Van + Anh; Clrscr; Writeln ('Phieu Bao Diem ') ; Writeln ('So bao danh : ', SBD); Writeln ('Diem van : ', Van); Writeln ('Diem toan : ', Toan); Writeln ('Diem ngoai ngu : ', Anh) ; Writeln ('Tong diem : ', Tongdiem); If Tongdiem >= 15 Then Writeln(' Ban da trung tuyen '); Else Writeln(' Ban khong trung tuyen '); Readln; END. 

Lesson 20: Enter 2 real numbers and calculate the calculation as required

Write a program to enter two real numbers. Then ask the calculation you want to perform and print the result of that calculation.

If it is "+", print two numbers on the screen.

If it is "-", print two numbers on the screen.

If it is "/", print two numbers on the screen.

If it is "*", print two numbers on the screen.

Sample code:

 Uses Crt; Var a, b, kq: Real; Pt: Char; BEGIN Clrscr; Write ('a ='); Readln(a); Write ('b ='); Readln(b); Write ('Phep tinh thuc hien la (+ - * /): '); Readln(Pt); If Pt = '+' Then kq := a + b; If Pt = '-' Then kq := a - b; If Pt = '*' Then kq := a * b; If Pt = '/' Then kq := a / b; Write (a, pt, b, '=', kq); Readln; END. 

This list of exercises will be updated, save it to make new posts.

See more:

  1. C ++ exercises have solutions (sample code)
  2. Basic Java exercises, with sample decoding
  3. More than 100 Python exercises have solutions (sample code)
3.5 ★ | 2 Vote