linkedin facebook linkedin facebook nod32

Borland C++ Builder siklik(takrorlanuvchi) algoritmlar

Muallif: Mengliyev Sh.

Qo`shilgan sana: 2015-05-30

Borland C++ Builder siklik(takrorlanuvchi) algoritmlar

1. Misol. N natural son va X haqiqiy sonlar berilgan. Quyidagi yig’indini hisoblang.

sin(x)+sin2(x)+...+sinn(x)Yechish. Izlanayotgan yig’indini S bilan belgilaymiz.

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int n,i;

Float x,s;
{
n=strtoint(edit1->text);
x=strtofloat(edit2->text);
s=0; x=sin(x);
for (i=1; i<n; i++)
s=s+exp(i*ln(x));
edit3->text=floattostr(s);
}

}

2. Misol. N! Aniqlansin. Bunda N natural son. Yechish.  N<34 bo’lganda natural sonlar faktorialini hisoblash mumkin.

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int n,i,f;
{
n=strtoint(edit1->Text);
f=1;
for (i=1; i<n; i++)
f=f*i;
edit2->Text:=inttostr(f);
}

}

3. Misol.1dan 20 gacha natural sonlar kvadratlari yig’indisini toping.

Yechish.  Izlanayotgan yig’indini S bilan belgilaymiz

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int n,i,f;
{
n=strtoint(edit1->Text);
f=0;
for (i=1; i<n; i++)
f=f+sqr(i);
edit2->Text:=inttostr(f);
}

}

4. Misol.A sonining N darajasini takrorlash buyrug’i yordamida hisoblang.

Yechish. A sonning n – darajasiga teng kattalikni  y bilan belgilaymiz

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int n,i;
{
n=strtoint(edit1->Text);
a=strtoint(edit2->Text);
f=1;
for (i=1; i<n; i++)
f:=f*a;
edit3->Text:=inttostr(f);
}

}

5. Misol.N natural son va A haqiqiy son berilgan. Quyidagi ko’paytmani hisoblang:
A(A+1)(A+2) ... (A+N)

Yechish. Berilgan ko’paytmani k bilan belgilaymiz

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int n,i;
Float a,p;
{
n=strtoint(edit1->Text);
a=strtoint(edit2->Text);
p=1;
for (i=0; i<n; i++)
p=p*(a+i);
edit3->Text:=inttostr(p);
}

}

6. Misol. Y=X2 ning [0,1] oraliqda 0,1 qadam bilan qiymatlar jadvalini aniqlang.

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int a,b;
float n,y,x;

String s1,s2;
{
a=strtoint(edit1->Text);
b=strtoint(edit2->Text);
n=strtofloat(edit3->Text); x=a;
memo1->Clear;
repeat y=sqr(x);
str(x:2,s1);str(y:5,s2);
memo1->lines->Add('x='+s1+'  y='+s2);
x=x+n;
until x>=b;
}

}

7. Misol.Y=3x2+4x-10 funksiyaning X o’zgaruvchi

1).  0,1,2,3,4,5;
2).  0,3,6,9,12 ga teng qiymatlarini qabul qilgandagi ifodalari hisoblansin.
Yechish. Dastlab x o’zgaruvchi 0,1,2,3,4,5 qiymatlarni  qabul qilgan hol uchun sikl operatoridan foydalanib dastur tuzamiz.

Borland C++ Builder da dasturu:

#include <math.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Int a,b;
Float n,y,x;

string s1,s2;
{
a=strtoint(edit1->Text);
b=strtoint(edit2->Text);
n=strtofloat(edit3->Text);
x=a; memo1->Clear;
repeat
y=3*sqr(x)+4*x-10; str(x:1,s1);str(y:5,s2);
memo1->lines->Add('x='+s1+'  y='+s2);
x=x+n;
until x>b;
}

}

2190 marta o`qildi.

Parol:
Eslab qolish.


Ro`yhatdan o`tish

testing

+998915878681

Siz o`z maxsulotingizni 3D reklama ko`rinishda bo`lishini xohlaysizmi? Unda xamkorlik qilamiz.

3D Reklama


Рейтинг@Mail.ru
Рейтинг@Mail.ru

Besucherzahler
счетчик посещений