Olimpiyada masalalarini yechish fani
I variant.
Musaboyeva (Ismoyilova) Surayyo
4Iòm 2- guruh
Masla-1. Agar
bolsa, u holda A, B, S raqamlarni topish dasturi tuzilsin.
Yechish:
Bu masalani yechish uchun onlik sanoq sistemasidagi sonlarni standart korinishini esga olish kifoya, yani:
AA + BB = A*10 + A + B*10 + B = (A+B)*10 + (A+B) = (A+B)*11
SBS = S*100 + B*10 + S = S*101 + B*10.
Shartga kora A, B, S lar raqam. Shuning uchun ularning qiymati 1 dan 9 gacha bolishi mumkin (nima uchun 0 bolishi mumkin emasligini ozingiz oylab koring).
Program Yigindi;
Uses Crt;
Var a,b,s:Integer;
Begin
TextColor(Yellow); TextBackGround(Blue);
ClrScr;
For a:=1 To 9 Do
Begin
For b:=1 To 9 Do
Begin
For s:=1 To 9 Do
Begin
If (11*(a+b))=(101*s+10*b) Then WriteLn('A=',a,' B=',b,' S=',s);
end;
end;
end;
ReadLn;
end.
Masala-2. A(n) butun qiymatli massiv elementlari ichida eng kop takrorlanganini toping. Bunday elementlar kop bolsa, bittasini chop eting.
Yechish:
Eng kop takrorlangan element qiymatini MAX bilan, tartib raqamini esa MAXN bilan belgilaymiz. Dasturi quyidagicha:
Program Eng_kop_takror;
Uses Crt;
Const n1=100;
Var a:Array[1..n1] of Integer;
max,maxn,sum:Integer;
i,j,n:Integer;
Begin
TextColor(Yellow); TextBackground(Blue); ClrScr;
WriteLn(' Massiv o`lchamini kiriting:');
Write(' N = ');ReadLn(n);
WriteLn(' 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],' element eng ko`p takrorlanadi');
ReadLn;
End.
Masala-3. a,b,c,d uzunlikdagi kesmalar berilgan. Agar ularning har uchtasidan uchburchak qurish mumkin bolsa, shu uchburchaklar yuzalarini chop etuvchi dastur tuzing.
Yechish:
Berilgan tort kesmadan kopi bilan tortta uchburchak hosil qilish mumkin (nima uchunligini oylab koring). Bu masalada kesmalar uchburchak hosil qilishi shartini tekshirishni va Geron formulasi yordamida yuza hisoblashni protsedura orqali bajaramiz. Dasturi quyidagicha:
Program Uchburchak;
Uses Crt;
var a,b,c,d:Integer;
yuza:Real;
Procedure Tekshir(x,y,z:Integer);
var p:Real;
Begin
If (x+y>z) And (x+z>y) And (y+z>x) Then
Begin
p:=(x+y+z)/2; yuza:=sqrt(p*(p-a)*(p-b)*(p-c));
WriteLn(x,',',y,' va ',z,' uzunlikdagi kesmalar ',yuza,' kv.birlik');
WriteLn('yuzali uchburchak hosil qiladi');
end
Else
Begin
WriteLn(x,',',y,' va ',z,' uzunlikdagi kesmalardan');
WriteLn('uchburchak hosil qilib bo`lmaydi');
end;
end;
Begin
TextColor(Yellow); TextBackground(Blue); ClrScr;
WriteLn('Kesma uzunliklarini kiriting:');
Write(' a = '); ReadLn(a);
Write(' b = '); ReadLn(b);
Write(' c = '); ReadLn(c);
Write(' d = '); ReadLn(d);
Tekshir(a,b,c); Tekshir(a,b,d); Tekshir(a,c,d); Tekshir(b,c,d);
ReadLn;
End.
Do'stlaringiz bilan baham: |