Misollar: 1. ax² + bx +c =0 ko’rinishidagi kvadrat tenglamani echish algoritmini tuzing. Bu erda a, b, c ≠ 0 deb qaralsin. Algoritmning blok sxemasini tuzamiz.
TARMOQLANUVCHI ALGORITM. KVADRAT TENGLAMANI YECHISH
Berilishi: ax2+bx+c=0
BOSHLANDI
a, b, c
D=b2-4ac
D=0
+
x=-b/2a
D<0
x
Yechim yo`q
x1, x2
x1=(-b+sqrt(d))/2a
x2=(-b-sqrt(d))/2a
-
TAMOM
+
-
1-variant: (goto bilan yozilgan) # include # include void main ( ) { float a, b, c, d, x, x1, x2; cout << “Tenglamaning koeffisientlarini kiriting: ”; cin >> a>>b>>c; d = b*b - 4*a*c; if ( d == 0 ) { x=- b / (2*a); cout <<”x=”<< x << endl; goto b15; } if ( d > 0 ) { x1 = (- b + sqrt(d)) / (2*a); x2 = (- b - sqrt(d)) / (2*a); cout <<”x1=”<< x1 <<” x2=” << x2 << endl; } else cout <<”еchimi yo’q!!!!”<< endl; b15 : } 2-variant. # include # include void main ( ) float a, b, c, d, x, x1, x2; cout << “Tenglamaning koeffisientlarini kiriting: \n”; cin >> a>>b>>c; d = b*b - 4*a*c; if ( d == 0 ) { x=- b / (2*a); cout <<”\n \t x=”<< x < 0 ) { x1 = (- b + sqrt(d)) / (2*a); x2 = (- b - sqrt(d)) / (2*a); cout <<” \n \t x1=”< 2- misol. 3ta haqiqiy sonlar berilgan. (x,y,z>0) Shu sonlar uzunliklaridan uchburchak yasab bo’ladimi? Agar yasab bo’lsa, qanday uchburchak hosil bo’ladi? (o’tkir burchakli, o’tmas burchakli, to’g’ri burchakli) # include # include void main ( ) { float x, y, z, max, d; cin >> x >> y >> z; if (x>y) max =x; else max = y; if (z>max) max = z; if (2*max < x+ y + z) { d = x*x + y*y + z*z – 2*max *max; if (d>0) cout << “o’tkir burchakli uchburchak”; if ( d = =0) cout << “to’g’ri burchakli uchburchak”; if (d< 0) cout << “o’tmas burchakli uchburchak”; } else cout << “uchburchak yasab bo’lmaydi!!!!”; getch ( ); } 0>
Do'stlaringiz bilan baham: |