Guruh Ollaberganov Mirzoxid Ollabergan O’g’li


Download 207.39 Kb.
Sana19.06.2023
Hajmi207.39 Kb.
#1615161
Bog'liq
1-amaliyot Ollaberganov Mirzoxid Ollabergan o\'g\'li


941-21 guruh Ollaberganov Mirzoxid Ollabergan O’g’li
1-AMALIY ISHI
Mavzu: Algoritmlarni loyixalashga kirish. Algoritm korrekt va samaradorligini baholash . Kvadrat tenglama ildizlarini aniqlash algoritmi. Uchburchak yuzasi uchun Geron formulasi.
Ishdan maqsad: Algoritmlarni samaradorligini baholash. Kvadrat va kubik tenglama ildizlarini aniqlash algoritmini ishlab chiqish.


Nazariy qism


Kvadrat tenglama ildizlarini aniqlash

Kvadrat tenglamaning ildizlarini topish vazifasi, boshqa ko'plab vazifalar singari, oson vazifadir. Uni qog’oz va qalam yordamida juda oson yechish mumkin, ammo algoritmni to’gri tanlab dasturini tuzish va undan foydalanish orqali yechimni avtomatlashtirish mumkin. Ushbu laboratoriyada biz shunday dastur algoritmini ko’rib chiqamiz.


Amaliyot topshiriqlari:
https://acmp.ru/index.asp?main=task&id_task=411 sayt bo’yicha masala


C++ kod
#include
#include
#include
using namespace std;
int main(){
double a,b,c;
cin>>a>>b>>c;
double d = b*b - 4*a*c;
if(a == 0 && b == 0 && c == 0){
cout<<-1;
}
else if(a == 0 && b != 0){
double x = -(c/b);
cout<<1<printf("%6f", x);
}
else if(a == 0 && b == 0 && c != 0){
cout<<0;
}
else if(d < 0){
cout<<0;
}
else if(d == 0){
double x = -(b/(2*a));
cout<<1<printf("%6f", x);
}
else{
double x1 = (-b - sqrt(d))/(2*a);
double x2 = (-b + sqrt(d))/(2*a);
cout<<2<printf("%6f", x1);
cout<printf("%6f", x2);
}
}



Java kod
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner son = new Scanner(System.in);

double a,b,c;


a = son.nextInt();
b = son.nextInt();
c = son.nextInt();
double d = Math.sqrt(b * b - 4 * a * c);
if (a == 0 && b == 0 && c == 0){
System.out.println(-1);
}
else if (a == 0 && b != 0){
double x = -(c/b);
System.out.println(1);
System.out.printf("%.6f",x);
}
else if (a == 0 && b == 0 && c != 0){
System.out.println(0);
}
else if (d < 0) {
System.out.println(0);
}
else if (d == 0) {
double x = -(c/b);
System.out.println(1);
System.out.printf("%.6f",x);
}
else {
double x1 = (-b - d)/(2*a);
double x2 = (-b + d)/(2*a);
System.out.println(2);
System.out.printf("%.6f",x1);
System.out.println();
System.out.printf("%.6f",x2);
}
}
}



Download 207.39 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling