Category Archives: Dasturlash tillari

Dasturlar yechimi

A[1..15] massiv berilgan. Massivning toq indeksli elementlarining yig’indisidan juft elementlarini ayirib chiqaruvchi dastur tuzing.

program dars34_mashq7;  uses crt; var a:array[1..15] of real;   toq,juft,s:real;   i:integer; begin  textcolor(14); textbackground(1); clrscr; for i:=1 to 15 do begin write(i,’-elementni kiriting:’); readln(a[i]); end; for i:=1 to 15 do begin  if odd(i) then toq:=toq+a[i] else juft:=juft+a[i]; end; s:=toq-juft;  write(‘Ayirma: ‘,s);  readln; end.

S=711+1721+2731+…+20072011 yig’indining hisoblash dasturini tuzing.

program dars34_mashq4; uses crt;  var s:real; i:integer; begin for i:=7 to 2007 do if (i mod 10)=7 then s:=s+i/(i+4); writeln(‘Yig`indi: ‘,s); readln; end.

y=x*sin x funksiyaning qiymatlarini [-π,π ] oraliqda 0,3 qadam bilan sonlarni chiqaruvchi dastur tuzing.

uses crt;  var x,y:real; begin  x:=-pi;  while x<=pi do begin y:=x*sin(x); writeln(‘x=’,x:1:2,’ bo`lganda y=’,y:1:2); x:=x+0.3; end; readln; end.

Ikki xonali natural sonlar ichida raqamlari yig’indisi juft bo’lgan sonlarni chiqaruvchi dastur tuzing.

1-usul

uses crt; var k,k1,k10,s:integer; begin  k:=10; while k<=99 do begin k1:= k mod 10; k10:=k div 10; s:=k1+k10;  if not(odd(s)) then writeln(k);k:=k+1; end; readln; end.

2-usul

uses crt; var k,k1,k10,s:integer; begin  k:=10;    repeat     k1:= k mod 10; k10:=k div 10; s:=k1+k10;  if not(odd(s)) then writeln(k);k:=k+1; until k>=99; end.

Berilgan butun N son musbat 6 ga karrali bo’lsa, shu sonning kvadrat ildizini, aks holda kvadratini hisoblash dasturini tuzing.

uses crt; var n:integer; begin write(‘N sonni kiriting: ‘); readln(n); if trunc(n/6)*6=n  then write(sqrt(n)) else write(sqr(n)); readln; end.

 

Dasturlar yechimi

Kvadrat tenglamaning yechilishi dasturini tuzing.

uses crt; label 1;  var    a,b,c,x1,x2,d:real;  begin        ClrScr;  write(‘Bosh koeffitsentni kiriting а= ‘);  readln(a);    write(‘Ikkinchi koeffitsentni kiriting b= ‘); readln(b);    write(‘Ozod hadni kiriting c= ‘);  read(c);    d:=sqr(b)-4*a*c;    if d<0 then begin writeln(‘Haqiqiy ildizlari yo`q.’); goto 1; end;

if d=0 then begin writeln(‘x1=x2= ‘,-b/2*a);  goto 1; end;    x1:=(-b+sqrt(d))/(2*a); x2:=(-b-sqrt(d))/(2*a);     writeln(‘x1=’,x1); writeln(‘x2=’,x2); 1: readln;     end.

Berilgan besh raqamli sonning polindram bo’lganligini aniqlang.

uses crt; var a1,b:string; i,a,len:longint; begin clrscr;  write(‘Sonni kiriting: ‘);  readln(a);

str(a,a1);  len:=length(a1);  for i:=1 to len do   b:=a1[i]+b;    if a1=b then write(‘bo`ladi’)

else write(‘bo`lmaydi’);   readln; end.

Berilgan natural sonni teskari tartibda yozish dasturini tuzing.

uses crt; var a,i,len:integer; b,c,teskari:string; begin write(‘Sonni kiriting: ‘); readln(a); str(a,c); len:=length(c); for i:=1 to len do begin  b:=copy(c,i,1); teskari:=b+teskari; end;  write(teskari); readln; ;end.

N natural sonni barcha bo’luvchilarini topuvchi dastur tuzing.

1-usul

var i,n:real;  begin  write(‘n=’); readln(n);  writeln(n,’ sonining bo`luvchilari: ‘);

i:=0; repeat i:=i+1; if trunc(n/i)*i=n then writeln(i); until i>n;  readln; end.

2-usul

uses crt; var i,n:longint;  begin textcolor(14); textbackground(1); clrscr; write(‘n=’); readln(n); writeln(n,’ sonining bo`luvchilari: ‘); for i:=1 to n do begin if trunc(n/i)*i=n then writeln(i); end; readln; end.

Hafta kunlari raqamlar bilan kiritilsa, so’zlar orqali natijaga chiqarish dasturi tuzilsin.

uses crt; label 1; var a:real; b:string; begin   write(‘Raqamni kiriting: ‘); readln(a); if not((a=1) or (a=2) or(a=3) or(a=4)or(a=5)or(a=6)or(a=7)) then  begin write(‘XATO’); goto 1; end; if a=1 then writeln(‘Dushanba’) else if a=2 then writeln(‘Seshanba’)else if a=3 then writeln(‘Chorshanba’) else if a=4 then writeln(‘Payshanba’) else if a=5 then writeln(‘Juma’)else if a=6 then writeln(‘Shanba’) else if a=7 then writeln(‘Yakshanba’); 1: readln; end.

 

Dasturlar yechimi

Istagan butun sonni 17 ga qoldiqsiz bo’linishi yoki bo’linmasligini aniqlovchi dastur tuzing.

Uses crt; Var a: integer; Begin ClrScr;  Write(‘a sonnni kiriting=’); readln(a);  If trunc(a/17)*17=a then writeln(‘bo`linadi.’) else writeln(‘bo`linmaydi.’); Readln; End.

Kvadratlari  berilgan  natural  N  sondan  katta  bo’lmagan  natural  sonlarni  chiqaruvchi dastur tuzing.

1-usul

Uses crt; Var I,N: integer; Begin ClrScr; Write(‘N ning qiymatini kiriting=’); readln(N); I:=1;

While I*I<=N do Begin writeln(I); I:=I+1; end; Readln; End.

2-usul

uses crt; var n,_n:real; begin textcolor(14); textbackground(1); clrscr; write(‘N sonini kiritng:’); readln(n); _n:=1; while n>sqr(_n) do begin _n:=_n+1; writeln(_n-1); end; readln; end.

Berilgan N natural sonning raqamlari yig’indisini topish dasturini tuzing.

1-usul

var n,raqam,len,i,c,natija: integer; _n,_raqam:string; begin write(‘Natural sonni kiriting:‘);readln(n);

str(n,_n); len:=length(_n); natija:=0; for:=1 to len do begin _raqam:=copy(n,i,1); val(_raqam,raqam,c); natija:=natija+raqam; end; writeln(n,’ sonining raqamlari yig’indisi=’,natija); readln; end.

2-usul

uses crt; var a,len,s,b,n:real; begin clrscr; readln(a); n:=0; while exp(n*ln(10))<a do n:=n+1; repeat

len:=exp((n-1)*ln(10)); b:=trunc(a/len); s:=s+b; a:=a-b*len; n:=n-1; until a<9; write(‘Raqamlari yig`indisi: ‘,s+a:1:0); readln; end.


A(N)  butun qiymatli massiv elementlari ichida eng ko’p takrorlanadigan elementlar sonini va o’sha elementni chop etuvchi dastur tuzing.

uses crt; const  n1=100; var a:array[1..n1] of integer;  max,maxn,sum:integer; I,j,n: integer; begin

writeln(‘Massiv elementlari sonini kiriting: ‘);   readln(n); write(‘massiv elementlarini kiriting: ‘);

for i:=1 to n do begin write(‘a(‘,i,’)=’); readln(a[i]); end; max:=1; maxn:=1; for i:=1 to n-1 do begin sum:=0; for j:=i+1 to n do  begin if a[i]=a[j] then inc(sum); end; if sum>max then

begin max:=sum; maxn:=i; end; end; writeln;    writeln(‘a(‘,maxn,’)=’,a[maxn],’  elementi eng ko`p takrorlanadi’);    writeln(max+1,’ marta ‘); readln;   end.

Berilgan kesmalardan uchburchakni hosil qilish mumkinligini tekshirish dasturini tuzing.

uses crt; label 1; var a,b,c:real; begin write(‘1-kesma uzunligini kiriting: ‘); readln(a);

write(‘2-kesma uzunligini kiriting: ‘); readln(b);write(‘3-kesma uzunligini kiriting: ‘); readln(c);

if (a+b>c) and (a+c>b) and (b+c>a) then begin writeln(‘Berilgan kesmalardan uchburchak hosil qilish mumkin’); goto 1; end else writeln(‘Berilgan kesmalardan uchburchak hosil qilib bo`lmaydi’);

1: readln; end.

 

Dasturlar yechimi

Uchta  sondan  kattasini  topish  dasturini  tuzing.  Buning  uchun  ikkita  sondan kattasini topish funksiyasini tuzib, undan foydalaning.

 

uses crt;  var i,max,a,b,c: integer;  function IKT(a,b:integer):integer;  var c:integer;

begin  if a>b then c:=a else c:=b;  IKT:=c;  end;  begin  write(‘1-sonni kiriting=’); readln(a);

write(‘2-sonni kiriting=’); readln(b);  write(‘3-sonni kiriting=’); readln(c);  a:=IKT(a,b); b:=c; max:=IKT(a,b);  writeln(‘Kattasi=’,max); readln;  end.

 

a,b,c sonlar berilgan. Ularning eng kattasi max(a,b,c) ni toping.

var a,b,c,nax: real; begin  write(‘a sonni kiriting: ‘) readln(a); write(‘b sonni kiriting: ‘) readln(b); write(‘c sonni kiriting: ‘) readln(c); if a>b then max:=a else max:=b if c>max then max:=c writeln(‘Berilgan uchta sondan kattasi = ‘,max); readln; end.

Ekranning to’rtta burchagida sariq rangli nuqta hosil qiluvchi dastur tuzing.

Uses graph; Var gd,gm: integer;  Begin  gd:=0;  InitGraph(gd,gm,»);  PutPixel(1,1,14); PutPixel(1,getmaxY,14);  PutPixel(getmaxX,1,14);PutPixel(getmaxX,getmaxY,14);  readln;

closegraph;  end.

Uchburchakning berilgan tomonlari bo’yicha uning balandliklarini aniqlovchi dastur tuzing.

Var a,b,c,ha,hb,hc:real; function h_ub(a,b,c:real); var yp,s:real; begin yp:=(a+b+c)/2;

s:=sqrt(yp*(yp-a)*(yp-b)*(yp-c)); H_UB:=2*s/a; end; begin write(‘Uchburchak tomonlari (a,b,c) kiriting: ‘); readln(a,b,c); ha:=h_ub(a,b,c); hb:=h_ub(b,a,c); hc:=h_ub(c,b,a); writeln(‘uchburchakning balandliklari: ‘); writeln(‘ha=’,ha,’hb=’,hb,’hc=’,hc); readln; end.

 

Ekranning o’rtasida radiusi 100 ga teng sariq rangli aylana chizing.

Uses wincrt, graph; label 1; Var gd,gm,i: integer;     y: char; Begin gd:=0; InitGraph(gd,gm,»);

Setcolor(14);  Circle(500,350,100); readln; closegraph;      end.

Dasturlar

12 xil bo’yash usulini namoyish etuvchi 40×40 o’lchamli 12 ta kvadrat chizing.

 

uses wincrt, graph, crt;  var i,gd,gm,x1,x2,y1,y2: integer;  begin gd:=0; clrscr;  initgraph(gd,gm,»);

x1:=1; x2:=40; y1:=1; y2:=40;  for i:=1 to 12 do  begin  setfillstyle(i,i+3); bar(x1,y1,x2,y2); x1:=x1+42; x2:=x2+42;  end;  readln;  closegraph;  end.

Hafta  kunlarining  nomlarini  kiritib,  ularni  «HAFTA.TXT»  faylida  saqlab  qo’yadigan dastur tuzing.

uses crt;  var kun: string; f: text;  i: integer; begin  clrscr; assign(f,’hafta.txt’);  rewrite(f);

for i:=1 to 7 do      begin      write(i,’-kun nomini kiriting=’);readln(kun);      writeln(f,kun);

end;  close(f);  readln;  end.

 

Ekran o’rtasidan bo’luvchi gorizontal chiziq chizuvchi dastur tuzing.

Uses wincrt, graph;  label 1;  Var gd,gm,i: integer;      y: char;  Begin  gd:=0;  InitGraph(gd,gm,»);

line(1,350,1000,350);  readln;  closegraph;   end.

 

Random funksiyasidan foydalanib, turli rangli nuqtalarni hosil qiling.

Uses wincrt, crt; graph; Var Gd,gm,x,y: integer;  Begin  Gd:=0; InitGraph(gd,gm,’’);  Randomize;

Repeat  X:=round(random(15)); y:=round(random(15));  Putpixel(50*x,50*y, x);  Until x=y+1;

Readln;  Closegraph;  End.

 

Random funksiyasidan foydalanib, «yulduzli osmon» manzarasini hosil  qiling.

uses graph; var gd,gm,x,y,k,i: integer;     begin     gd:=0;     initgraph(gd,gm,»); randomize;     repeat

for i:=1 to 15 do     begin     x:=25*k*round(random(15));     y:=20*k*round(random(15));

putpixel(x,y,i);     end;     k:=k+1;     until k>10;     readln; closegraph;  end.