1. Trang chủ
  2. » Giáo án - Bài giảng

lập trình pascal các bạn xem nhá

9 325 1

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 9
Dung lượng 40,5 KB

Nội dung

Tính giá tri c?a t?ng sau: A1 + a2 +a3 +… +ak program bai1; uses crt; var n,k,i:integer; s: real; function mu(a,k:integer):real; var gt:real; begin gt:=exp(k*ln(a)); mu:=gt; end; begin clrscr; write('nhap vao n va k'); readln(n,k); if n or k< 0 then write(' nhap lai n va k') else s:=0; for i:=1 to n do s:= s+ mu(i,k); write('gia tri cua tong la',s:5:0); readln; end. program bai2; uses crt; var s,i,n:integer; function giaithua(a:integer):integer; var i,gt:integer; begin gt:=1; for i:=1 to a do gt:=gt*i; giaithua:=gt; end; begin clrscr; write('nhap n '); readln(n); s:=0; for i:=1 to n do s:=s+giaithua(i); write('gia tri cua day la',s); readln; end. program bai3; var a,b,c:array[1 5,1 5]of integer; n,i,j:integer; begin write('nhap n'); readln(n); for i:=1 to n do for j:=1 to n do begin write('a[',i,'][',j,']='); readln(a[i,j]); end; for i:=1 to n do for j:=1 to n do begin write('b[',i,'][',j,']'); readln(b[i,j]); end; for i:=1 to n do for j:=1 to n do begin c[i,j]:=a[i,j]+b[i,j]; end; for i:=1 to n do begin for j:=1 to n do write(c[i,j]); writeln; end; readln; end. program bai4; var a:array[1 10] of real; b,c,n,i:integer; tbca:real; tbcd:real; begin write('nhap n '); readln(n); for i:=1 to n do begin write('a[',i,']'); readln(a[i]); end; tbca:=0; b:=0; for i:=1 to n do begin if a[i]<0 then begin tbca:=tbca+a[i]; b:=b+1; end; end; tbcd:=0; c:=0; for i:=1 to n do begin if a[i]>0 then begin tbcd:=tbcd+a[i]; c:=c+1; end; end; writeln('trung binh cong so am = ',tbca/b:7:1); writeln('trung bing cong so duong = ',tbcd/c:7:1); readln; end. ‘ program bai6; var n,i:integer; s,x:real; function giaithua(k:integer):integer; var i,gt:integer; begin gt:=1; for i:=1 to n do gt:=gt*i; giaithua:=gt; end; function mu(x:real;k:integer):real; var w:real; begin w:=exp(k*ln(x)); mu:=w; end; function dandau(i:integer):integer; var q:integer; begin if i mod 2=0 then q:=-1 else q:=1; dandau:=q; end; begin write('nhap n va x'); readln(n,x); s:=x; for i:=2 to n do s:=s+(dandau(i)*mu(x,2*i-1))/giaithua(2*i-1); write('sin(x)=',s:5:6); readln; end. program bai7; var a:array[1 100] of integer; n,i,c,l,sc,sl:integer; begin write('nhap n'); readln(n); for i:=1 to n do begin write('a[',i,']'); readln(a[i]); end; sc:=0;c:=0;sl:=0;l:=0; for i:=1 to n do begin if a[i] mod 2 = 0 then begin sc:=sc+a[i]; c:=c+1; end else begin sl:=sl+a[i]; l:=l+1; end; end; write('trung binh cong chan la',(sc/c):6:3); write('trung binh cong le la',(sl/l):6:3); readln; end. program bai8; var a:array[1 50] of integer; n,i,min,max:integer; begin write('nhap n'); readln(n); for i:=1 to n do begin write('a[',i,']'); readln(a[i]); end; min:=a[1];max:=a[1]; for i:=2 to n do begin if a[i]<min then min:=a[i]; if a[i]>max then max:=a[i]; end; write('min mang la',min); write('max mang la',max); readln; end. program bai9; var a:array[1 100] of integer; n,i,dem,s:integer; begin write('nhap n '); readln(n); for i:=1 to n do begin write('a[',i,']'); readln(a[i]); end; dem:=0;s:=0; for i:=1 to n do begin if a[i]>0 then begin s:=s+a[i]; dem:=dem+1; end; end; write('tong cua cac so duong la',s); write('so so duong co trong day la',dem); readln; end. program bai11; var d,x,i,n:integer; s:real; function mu(a,b:integer):real; var gt:real; begin gt:=exp(b*ln(a)); mu:=gt; end; begin write('nhap n va x'); readln(n,x); s:=1;d:=1; for i:=1 to n do begin s:=s+mu(x,i)/d; d:=d+1; end; write('gia tri cua day so la',s:5:3); readln; end. program bai12; var n,i:integer; x,s:real; function giaithua(n:integer):integer; var tg:integer; begin tg:=1; for i:=1 to n do tg:=tg*i; giaithua:=tg; end; function mu(a:real;b:integer):real; var gt:real; begin gt:=exp(b*ln(a)); mu:=gt; end; function dandau(i:integer):integer; var q:integer; begin if i mod 2=0 then q:=1 else q:=-1; dandau:=q; end; begin write('nhap n va x'); readln(n,x); s:=s; for i:=1 to n do s:=s+(dandau(i)*mu(x,i))/giaithua(i); write('tong chuoi la',s:5:5); readln; end. program bai14; var n,i:integer; s,x:real; function giaithua(k:integer):integer; var i,gt:integer; begin gt:=1; for i:=1 to n do gt:=gt*i; giaithua:=gt; end; function mu(x:real;k:integer):real; var w:real; begin w:=exp(k*ln(x)); mu:=w; end; begin write('nhap n va x'); readln(n,x); s:=1; for i:=1 to n do s:=s+mu(x,i)/giaithua(i); write('tong day so la',s:5:3); readln; end. program bai15; var a:array[1 100,1 100]of integer; n,s,i,j:integer; begin write('nhap n '); readln(n); for i:=1 to n do for j:=1 to n do begin write('a[',i,'][',j,']'); readln(a[i,j]); end; s:=0; for i:=1 to n do for j:=1 to n do begin if i=j then s:=s+a[i,j]; end; writeln('tong cac so duong cheo chinh la',s); for i:=1 to n do begin for j:=1 to n do write(a[i,j]); writeln; end; readln; end. program bai16; var a,b,c:real; w:integer; function dientich(a,b,c:real):real; var p,s:real; begin p:=(a+b+c)/2; s:=sqrt(p*(p-a)*(p-b)*(p-c)); dientich:=s; end; function chuvi(a,b,c:real):real; var p:real; begin p:=a+b+c; chuvi:=p; end; function tinhchat(a,b,c:real):integer; var tc:integer; begin if (a=b) and (b=c) then tc:=1; if (a=b)or (b=c) or (a=c) then tc:=2; if (a*a=b*b+c*c) or (b*b=a*a+c*c) or (c*c=a*a+b*b) then tc:=3; tinhchat:=tc; end; begin write('nhap a b c '); readln(a,b,c); if (a>0) and (b>0) and (c>0) and (a<b+c) and (b<a+c) and (c<a+b) then begin w:=tinhchat(a,b,c); case w of 1:writeln('tam giac da cho la tam giac deu'); 2:writeln('tam giac da cho la tam giac can'); 3:writeln('tam giac da cho la tam giac vuong '); end; writeln('dien tich tam giac da cho la',dientich(a,b,c):5:2); writeln('chu vi tam giac da cho la',chuvi(a,b,c):5:2); end else write(' 3 so a,b,c khong tao thanh tam giac') ; readln; end. program bai19; var a,b:array[1 100] of real; n,i,k:integer; x,y:real; begin write('nhap vao x y k n'); readln(x,y,k,n); for i:=1 to n do begin write('a[',i,']'); readln(a[i]); end; for i:=1 to n+2 do begin if i<k then b[i]:=a[i]; if i=k then b[i]:=x; if i=k+1 then b[i]:=y; if i>k+1 then b[i]:=a[i-2]; end; for i:=1 to n do writeln('a[',i,']',a[i]:5:0); for i:=1 to n+2 do writeln('b[',i,']',b[i]:5:0); readln; end. program bai20; var a,b:array[1 100] of real; n,i,k:integer; x,y:real; begin write('nhap vao x y k n'); readln(x,y,k,n); for i:=1 to n do begin write('a[',i,']'); readln(a[i]); end; for i:=1 to n do begin if i<k then b[i]:=a[i]; if i>k then b[i-1]:=a[i]; end; for i:=1 to n do writeln('a[',i,']=',a[i]:5:0); for i:=1 to n-1 do writeln('b[',i,']= ',b[i]:5:0); readln; end.

Ngày đăng: 17/06/2015, 01:00

TỪ KHÓA LIÊN QUAN

w