Trang chủ
Bài viết mới
Diễn đàn
Bài mới trên hồ sơ
Hoạt động mới nhất
VIDEO
Mùa Tết
Văn Học Trẻ
Văn Học News
Media
New media
New comments
Search media
Đại Học
Đại cương
Chuyên ngành
Triết học
Kinh tế
KHXH & NV
Công nghệ thông tin
Khoa học kĩ thuật
Luận văn, tiểu luận
Phổ Thông
Lớp 12
Ngữ văn 12
Lớp 11
Ngữ văn 11
Lớp 10
Ngữ văn 10
LỚP 9
Ngữ văn 9
Lớp 8
Ngữ văn 8
Lớp 7
Ngữ văn 7
Lớp 6
Ngữ văn 6
Tiểu học
Thành viên
Thành viên trực tuyến
Bài mới trên hồ sơ
Tìm trong hồ sơ cá nhân
Credits
Transactions
Xu: 0
Đăng nhập
Đăng ký
Có gì mới?
Tìm kiếm
Tìm kiếm
Chỉ tìm trong tiêu đề
Bởi:
Hoạt động mới nhất
Đăng ký
Menu
Đăng nhập
Đăng ký
Install the app
Cài đặt
Chào mừng Bạn tham gia Diễn Đàn VNKienThuc.com -
Định hướng Forum
Kiến Thức
- HÃY TẠO CHỦ ĐỀ KIẾN THỨC HỮU ÍCH VÀ CÙNG NHAU THẢO LUẬN Kết nối:
VNK X
-
VNK groups
| Nhà Tài Trợ:
BhnongFood X
-
Bhnong groups
-
Đặt mua Bánh Bhnong
CÔNG NGHỆ
Công Nghệ Thông Tin
Hỏi đáp Tin học
Mảng 1 chiều?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Trả lời chủ đề
Nội dung
<blockquote data-quote="dienvi2010" data-source="post: 125219" data-attributes="member: 11277"><p>Bài tập code tham khảo - Sử dụng chương trình con</p><p></p><p>[php]</p><p>Program BTMang;</p><p>Const Max = 20;</p><p>Var a : array[1..Max] of integer;</p><p> n:byte; kt:integer;</p><p></p><p>{---Nhap mang---}</p><p>Procedure Nhap;</p><p>Var i:byte;</p><p>Begin</p><p> Write('Nhap n phan tu (1<1n<=20): '); Readln(n);</p><p> for i:=1 to n do</p><p> begin</p><p> write('a[',i,']: ');</p><p> readln(a[i]);</p><p> end;</p><p>End;</p><p>{---In so le---}</p><p>Procedure InSoLe;</p><p>Var i:byte;</p><p>Begin</p><p> for i:=1 to n do</p><p> if a[i] mod 2=1 then</p><p> write(a[i]:5);</p><p> writeln;</p><p>End;</p><p>{---Kiem tra so nguyen to---}</p><p>Function KTNguyenTo(k:integer):boolean;</p><p>Var i:integer; dem:byte;</p><p>Begin</p><p> if (n=1) or (n=2) then</p><p> KTNguyenTo:=false</p><p> else</p><p> begin</p><p> dem:=0;</p><p> for i:=2 to k do</p><p> begin</p><p> if (k mod i)=0 then</p><p> dem:=dem+1 ;</p><p> end;</p><p> if dem >1 then</p><p> KTNguyenTo:=false</p><p> else</p><p> KTNguyenTo:=true;</p><p></p><p> end;</p><p>End;</p><p>{---In so nguyen to---}</p><p>Procedure InSoNT;</p><p>Var i: byte;</p><p>Begin</p><p> for i:=1 to n do</p><p> if KTNguyenTo(a[i])=true then</p><p> write(a[i]:5);</p><p> writeln;</p><p>End;</p><p>Function SoChanLonNhat:integer;</p><p>Var i,max:integer;</p><p>Begin</p><p> max:=-1;</p><p> for i:=2 to n do</p><p> if (a[i] mod 2 =0) and (a[i]>max) then max:=a[i];</p><p> SoChanLonNhat:=max;</p><p>End;</p><p>Begin</p><p> Nhap;</p><p> write('Day so le: ');</p><p> InSoLe;</p><p> write('Day so nguyen to: ');</p><p> InSoNT;</p><p> kt:=SoChanLonNhat;</p><p> if kt=-1 then</p><p> writeln('Khong co so chan lon nhat.')</p><p> else</p><p> writeln('So chan lon nhat la: ',kt);</p><p> readln;</p><p>End.</p><p>[/php]</p></blockquote><p></p>
[QUOTE="dienvi2010, post: 125219, member: 11277"] Bài tập code tham khảo - Sử dụng chương trình con [php] Program BTMang; Const Max = 20; Var a : array[1..Max] of integer; n:byte; kt:integer; {---Nhap mang---} Procedure Nhap; Var i:byte; Begin Write('Nhap n phan tu (1<1n<=20): '); Readln(n); for i:=1 to n do begin write('a[',i,']: '); readln(a[i]); end; End; {---In so le---} Procedure InSoLe; Var i:byte; Begin for i:=1 to n do if a[i] mod 2=1 then write(a[i]:5); writeln; End; {---Kiem tra so nguyen to---} Function KTNguyenTo(k:integer):boolean; Var i:integer; dem:byte; Begin if (n=1) or (n=2) then KTNguyenTo:=false else begin dem:=0; for i:=2 to k do begin if (k mod i)=0 then dem:=dem+1 ; end; if dem >1 then KTNguyenTo:=false else KTNguyenTo:=true; end; End; {---In so nguyen to---} Procedure InSoNT; Var i: byte; Begin for i:=1 to n do if KTNguyenTo(a[i])=true then write(a[i]:5); writeln; End; Function SoChanLonNhat:integer; Var i,max:integer; Begin max:=-1; for i:=2 to n do if (a[i] mod 2 =0) and (a[i]>max) then max:=a[i]; SoChanLonNhat:=max; End; Begin Nhap; write('Day so le: '); InSoLe; write('Day so nguyen to: '); InSoNT; kt:=SoChanLonNhat; if kt=-1 then writeln('Khong co so chan lon nhat.') else writeln('So chan lon nhat la: ',kt); readln; End. [/php] [/QUOTE]
Tên
Mã xác nhận
Gửi trả lời
CÔNG NGHỆ
Công Nghệ Thông Tin
Hỏi đáp Tin học
Mảng 1 chiều?
Top