Admin Admin
Tổng số bài gửi : 25 Điểm học tập : 4181 Được Cảm Ơn : 0 Join date : 23/02/2013 Age : 24 Đến từ : TPHCM
| Tiêu đề: Đếm số nguyên tổ trong mảng 1 chiều Wed Jun 19, 2013 1:47 pm | |
| - Code:
-
[color=#333333][font='Courier New', Courier, monospace]var i,j,n:Integer;[/font][/color] [color=#333333][font='Courier New', Courier, monospace] A:array[1..50] of Integer;[/font][/color] [color=#333333][font='Courier New', Courier, monospace]begin[/font][/color] [color=#333333][font='Courier New', Courier, monospace] write('nhap n:');[/font][/color] [color=#333333][font='Courier New', Courier, monospace] readln(n);[/font][/color] [color=#333333][font='Courier New', Courier, monospace] for i:=1 to n do[/font][/color] [color=#333333][font='Courier New', Courier, monospace] begin[/font][/color] [color=#333333][font='Courier New', Courier, monospace] write('nhap a[',i,'] ');[/font][/color] [color=#333333][font='Courier New', Courier, monospace] readln(a[i]);[/font][/color] [color=#333333][font='Courier New', Courier, monospace] end;[/font][/color] [color=#333333][font='Courier New', Courier, monospace] j:=1;[/font][/color] [color=#333333][font='Courier New', Courier, monospace] for i:=1 to n do[/font][/color] [color=#333333][font='Courier New', Courier, monospace] if a[i]>1 then[/font][/color] [color=#333333][font='Courier New', Courier, monospace] begin[/font][/color] [color=#333333][font='Courier New', Courier, monospace] repeat[/font][/color] [color=#333333][font='Courier New', Courier, monospace] inc(j);[/font][/color] [color=#333333][font='Courier New', Courier, monospace] until (a[i] mod j=0);[/font][/color] [color=#333333][font='Courier New', Courier, monospace] if j>(a[i] div 2) then inc(d);[/font][/color] [color=#333333][font='Courier New', Courier, monospace] j:=1;[/font][/color] [color=#333333][font='Courier New', Courier, monospace] end;[/font][/color] [color=#333333][font='Courier New', Courier, monospace] write('Co ',d,' so ngto trog day');[/font][/color] [color=#333333][font='Courier New', Courier, monospace] readln;[/font][/color] [color=#333333][font='Courier New', Courier, monospace]end.[/font][/color] | |
|