Kiểm tra giúp mik với ja, mik sai chỗ nào mà nó không ra số lượng số nguyên tố vậy ạ? Uses CRT; Var a: Array [1..100] of Integer; i,n,p,s: Integer; Function ktnt (n: Integer): Boolean; Var i,d,p: Integer; Begin d:=0; If n<2 then ktnt:=false Else Begin p:=0; For i:=1 to n do If n mod i=0 then d:=d+1; End; If d=2 then ktnt:=true Else ktnt:=false; End; Function kthh (n:Integer): Boolean; Var i,s: Integer; Begin s:=0; For i:=1 to n div 2 do If n mod i=0 then s:=s+i; If s=n then kthh:=true Else kthh:=false; End; Begin ClrScr; Write ( 'Nhap so nguyen n: '); Readln (n); For i:=1 to n do Begin Write ( 'Nhap phan tu thu ',i,': '); Readln (a[i]); End; Write ( 'Cac so nguyen to co trong day tren la: ' ); For i:=1 to n do Begin If ktnt (a[i])=true then Begin Write (a[i],' '); End; End; For i:=1 to n do If ktnt (a[i])=true then p:=p+1; Writeln; Write ( 'Cac so hoan hao co trong day tren la: '); For i:=1 to n do If kthh (a[i])=true then Write(a[i],' '); Readln; End.

2 câu trả lời

bài của bạn thiếu câu lệnh in ra số các số nguyên tố nha

mình bổ sung thêm vào rùi đó

Uses CRT;
Var a: Array [1..100] of Integer;
i,n,p,s: Integer;
Function ktnt (n: Integer): Boolean;
Var i,d,p: Integer;
Begin
  d:=0;
  If n<2 then
   ktnt:=false
  Else
   Begin
    p:=0;
    For i:=1 to n do
     If n mod i=0 then
      d:=d+1;
   End;
  If d=2 then
   ktnt:=true
  Else
   ktnt:=false;
End;
Function kthh (n:Integer): Boolean;
Var i,s: Integer;
Begin
  s:=0;
  For i:=1 to n div 2 do
    If n mod i=0 then
     s:=s+i;
    If s=n then
     kthh:=true
    Else
     kthh:=false;
End;
Begin
  ClrScr;
  Write ( 'Nhap so nguyen n: ');
  Readln (n);
  For i:=1 to n do
   Begin
    Write ( 'Nhap phan tu thu ',i,': ');
    Readln (a[i]);
   End;
  Write ( 'Cac so nguyen to co trong day tren la: ' );
  For i:=1 to n do
   Begin
    If ktnt (a[i])=true then
     Begin
      Write (a[i],' ');
     End;
   End;
  For i:=1 to n do
   If ktnt (a[i])=true then
   p:=p+1;
  Writeln;
  writeln('Co ',p,' so nguyen to');
  Write ( 'Cac so hoan hao co trong day tren la: ');
  For i:=1 to n do
    If kthh (a[i])=true then
     Write(a[i],' ');
  Readln;
End.
Uses CRT;
Var a: Array [1..100] of Integer;
i,n,p,s: Integer;
Function ktnt (n: Integer): Boolean;
Var i,d,p: Integer;
Begin
  d:=0;
  If n<2 then
   ktnt:=false
  Else
   Begin
    p:=0;
    For i:=1 to n do
     If n mod i=0 then
      d:=d+1;
   End;
  If d=2 then
   ktnt:=true
  Else
   ktnt:=false;
End;
Function kthh (n:Integer): Boolean;
Var i,s: Integer;
Begin
  s:=0;
  For i:=1 to n div 2 do
    If n mod i=0 then
     s:=s+i;
    If s=n then
     kthh:=true
    Else
     kthh:=false;
End;
Begin
  ClrScr;
  Write ( 'Nhap so nguyen n: ');
  Readln (n);
  For i:=1 to n do
   Begin
    Write ( 'Nhap phan tu thu ',i,': ');
    Readln (a[i]);
   End;
  Write ( 'Cac so nguyen to co trong day tren la: ' );
  For i:=1 to n do
   Begin
    If ktnt (a[i])=true then
     Begin
      Write (a[i],' ');
     End;
   End;
  For i:=1 to n do
   If ktnt (a[i])=true then
   p:=p+1;
  Writeln;
  writeln('Co ',p,' so nguyen to');
  Write ( 'Cac so hoan hao co trong day tren la: ');
  For i:=1 to n do
    If kthh (a[i])=true then
     Write(a[i],' ');
  Readln;
End.


Pascal là ngôn ngữ khá cũ, trong thực tế nó không còn được sử dụng phổ biến như trước nữa. So với các ngôn ngữ lập trình script hiện đại thì Pascal khá dài dòng, mức độ trừu tượng cao và cách code khá giống với ngôn ngữ lập trình C. Hầu hết các chương trình C đều có thể dịch được sang Pascal mà chỉ bị thay đổi về cú pháp chứ không làm thay đổi cấu trúc. Mà C thì là một trong những ngôn ngữ lập trình rất phổ biến, do đó nắm được Pascal bạn sẽ tiếp cận C tốt hơn. Nó cũng buộc bạn phải luôn nghĩ về kiểu dữ liệu, điều này sẽ giúp các lập trình viên mới học được một thói quen tuyệt vời khi code.

Và vì không có nhiều giá trị thương mại, Pascal được sử dụng chủ yếu để dạy nhập môn lập trình hoặc dành cho những người yêu thích Pascal tìm tòi. Nếu bạn thích lập trình, mới học nhưng không "hấp thụ" được Pascal có thể thử Python nhé.

Dưới đây là tổng hợp một số bài tập Pascal từ cơ bản đến phức tạp hy vọng việc học của bạn sẽ dễ dàng hơn đôi chút.

Bài 1: In số chẵn ra màn hình

Viết chương trình nhập vào 1 số N nguyên dương và in ra màn hình các số chẵn từ 0 đến N, sao cho mỗi số chiếm 4 vị trí và 1 dòng có 15 số.

Câu hỏi trong lớp Xem thêm

A. Read the passage and choose the best answer (A, B, or C) to the following questions (5 pts) My name is Hoa. Here is a photo of my school. It is a big school. It is in Hue. It is on Nguyen Hue Street. In my school, there is a big yard and there are a lot of trees around it. My school has three floors and forty classrooms with 1,700 students. My classroom is on the second floor. I‟m in grade 7, class 7A. Our class starts at 7.00 and finishes at 11.30. At school we learn many things, but I like Literature and English best. I also like Music, Sports and Art. We often have recess at 9.20. We usually drink, eat and talk at recess. We sometimes play games like blind man‟s bluff or catch. We often make much noise at recess. After school, we often go home and have lunch at 12.30. 1. Where is the school? A. On Nguyen Hue Street B. In Hue C. On Nguyen Hue Street in Hue 2. How many students are there in the school? A. 1,700 B. 1,070 C. 1,007 3. When does the class start and finish? A. 7.00 and 11.00 B. 7.30 and 11.00 C. 7.00 and 11.30 4. What subjects does she like best? A. Literature and English B. Literature and Art C. English and Music 5. What does she usually do at recess? A. Drinks and eats B. Drinks, eats and talks C. Eats and talks VII. Reading B. Read the passage and choose the best answer (A, B, or C) to the following questions (5 pts) What do you often do after school? In my school, there are a lot of clubs which students can take part in after school hours. The club that has the biggest number of members is the swimming club called “Blue Dolphins”. I myself love swimming so I am a member of this club. I go to the swimming pool twice a day and swim for about an hour. I‟m really interested in swimming breaststroke because it helps me move as fast as I can. I‟m also fond of backstroke. I swim backstroke when I want to relax, breathe and let my body float freely. It‟s very relaxing. The second club I would like to mention is the charity club. Its name is “Golden Heart”. Members of the club often do community service. This month, they are conducting a clean-up campaign to protect the environment around the school. They collect trash, clean the toilet area, and grow plants. I am not a Golden Heart‟s member, but I participate in their activities whenever I can. If you can sing, dance or play musical instruments, the musical club “Heartstrings” is definitely for you. The president of the club is Mike, my best friend. He is not only good-looking but also sings beautifully and plays the guitar very well. In conclusion, we should do as many activities as possible in our free time to have good health and a fresh mind to prepare for lessons in class. Spending all our time studying is not a good idea. 6. The writer is interested in swimming breaststroke because ________ A. it makes him relaxed B. it helps him swim as fast as he can C. it helps him stay healthy D. it is the easiest swimming style 7. The writer is fond of backstroke when ________ . A. he has a competition B. he is hot C. he is tired D. he want to relax 8. This month, Golden Heart's members ________ . A. clean classrooms, halls, and the toilet area B. grow plants, water flowers C. help elderly people D. collect trash, clean the toilet area, and grow plants 9. The musical club “Heartstrings” is definitely for the students who ________ . A. can sing and dance B. can sing, dance, and play musical instruments C. can write songs D. can cook 10. Spending all the time studying is ________ . A. unnecessary B. necessary C. good D. important

4 lượt xem
2 đáp án
16 giờ trước