C# dasturlash tilida:
using System;
namespace Atenglama._1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("1- tenglama keoffitsientlarini kiriting: (ax + by = c):");
Console.Write("a1 ni kiriting: ");
double a1 = Convert.ToDouble(Console.ReadLine());
Console.Write("b1 ni kiriting: ");
double b1 = Convert.ToDouble(Console.ReadLine());
Console.Write("c1 ni kiriting: ");
double c1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\n 2- tenglama keoffitsientlarini kiriting (dx + ey = f):");
Console.Write("a2 ni kiriting: ");
double a2 = Convert.ToDouble(Console.ReadLine());
Console.Write("b2 ni kiriting: ");
double b2 = Convert.ToDouble(Console.ReadLine());
Console.Write("c2 ni kiriting: ");
double c2 = Convert.ToDouble(Console.ReadLine());
// Tenglamalar sistemasini yechish
double determinant = a1 * b2 - a2 * b1;
if (determinant == 0)
{
Console.WriteLine("Sistema yagona yechimga ega emas(Yoki cheksz ko'p yechimga ega):");
}
else
{
double x = (c1 * b2 - c2 * b1) / determinant;
double y = (a1 * c2 - a2 * c1) / determinant;
Console.WriteLine($"\n Javob: x = {x}, y = {y}");
}
Console.ReadKey();
}
}
}
C++ dasturlash tilida.
#include
int main()
{
double a1, b1, c1, a2, b2, c2;
// 1- tenglama keoffitsientlarini foydalanuvchidan olish (a1x + b1y = c1)
std::cout << "1- tenglama keoffitsientlarini kiriting (a1x + b1y = c1):" << std::endl;
std::cout << "a1 ni kiriting: ";
std::cin >> a1;
std::cout << "b1 ni kiriting: ";
std::cin >> b1;
std::cout << "c1 ni kiriting: ";
std::cin >> c1;
// 1- tenglama keoffitsientlarini foydalanuvchidan olish (a2x + b2y = c2)
std::cout << "\n 1- tenglama keoffitsientlarini kiriting(a2x + b2y = c2):" << std::endl;
std::cout << "a2 ni kiriting: ";
std::cin >> a2;
std::cout << "b2 ni kiriting: ";
std::cin >> b2;
std::cout << "c2 ni kiriting: ";
std::cin >> c2;
// Sistemani yechish
double determinant = a1 * b2 - a2 * b1;
if (determinant == 0)
{
std::cout << "Sistema yagona yechimga ega emas(Yoki cheksz ko'p yechimga ega)." << std::endl;
}
else
{
double x = (c1 * b2 - c2 * b1) / determinant;
double y = (a1 * c2 - a2 * c1) / determinant;
std::cout << "\nJavob: x = " << x << ", y = " << y << std::endl;
}
return 0;
}
JAVA dasturlash tilida.
using System;
import java.util.Scanner;
public class SystemOfEquationsSolver
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
double a1, b1, c1, a2, b2, c2;
// Birinchi tenglama uchun foydalanuvchidan koeffitsientlarni olish (a1x + b1y = c1)
System.out.println("1-tenglama uchun koeffitsientlarni kiriting (a1x + b1y = c1):");
System.out.print("a1 ni kiriting: ");
a1 = scanner.nextDouble();
System.out.print("b1 ni kiriting: ");
b1 = scanner.nextDouble();
System.out.print("c1 ni kiriting: ");
c1 = scanner.nextDouble();
// Ikinchi tenglama uchun foydalanuvchidan koeffitsientlarni olish (a2x + b2y = c2)
System.out.println("\n 2-tenglama uchun koeffitsientlarni kiriting (a2x + b2y = c2):");
System.out.print("a2 ni kiriting: ");
a2 = scanner.nextDouble();
System.out.print("b2 ni kiriting: ");
b2 = scanner.nextDouble();
System.out.print("c2 ni kiriting: ");
c2 = scanner.nextDouble();
// Tenglamani yechish
double determinant = a1 * b2 - a2 * b1;
if (determinant == 0)
{
System.out.println("Sistema yagona yechimga ega emas(Yoki cheksz ko'p yechimga ega)");
}
else
{
double x = (c1 * b2 - c2 * b1) / determinant;
double y = (a1 * c2 - a2 * c1) / determinant;
System.out.println("\nJavob: x = " + x + ", y = " + y);
}
scanner.close();
}
}
|