Metziop

Untitled

May 24th, 2023
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using Xamarin.Forms;
  8. using Xamarin.Forms.Xaml;
  9.  
  10. namespace Regla_Cramer
  11. {
  12.     [XamlCompilation(XamlCompilationOptions.Compile)]
  13.     public partial class Resulltado : ContentPage
  14.     {
  15.         public Resulltado(double x1, double x2, double y1, double y2, double r1, double r2 )
  16.         {
  17.             InitializeComponent();
  18.  
  19.             try {
  20.                 //calculando viabilidad de la ecuación
  21.                 double e = Calcular(x1, x2, y1, y2);
  22.                 if (Math.Abs(e) < 1E-10)
  23.                 {
  24.                     DisplayAlert("Error", "El sistema no tiene solución", "OK");
  25.                 }
  26.                 //calculando solución
  27.                 else
  28.                 {
  29.                     double Dx = Calcular(r1, y1, r2, y2);
  30.                     double Dy = Calcular(x1, r1, x2, r2);
  31.                     e1.Text = $"   X1={x1}  Y1={y1} = {r1}";
  32.                     e2.Text = $"   X2={x2}  Y2={y2} =  {r2}";
  33.                     ds.Text = $"    D=({x1}*{y2})-({y2}*{x2})={e}";
  34.                     double x = Dx / e;
  35.                     double y = Dy / e;
  36.                     dx.Text = $"Dx= ({r1}*{y2})-({y1}*{r2})={Dx}";
  37.                     dy.Text = $"Dy= ({x1}*{r2})-({r1}*{x2})={Dy}";
  38.                     //calculando resultados
  39.                     xF.Text = $" X= {Dx}/{e}={x}";
  40.                     yF.Text = $"Y= {Dy}/{e}={y}";
  41.  
  42.                 }
  43.  
  44.             } catch (DivideByZeroException) {
  45.                 DisplayAlert("Error", "Division por 0", "OK");
  46.  
  47.             }catch (Exception ex)
  48.             {
  49.                 DisplayAlert("Error", ex.Message, "OK");
  50.             }
  51.  
  52.         }
  53.         private double Calcular(double x1, double x2, double y1, double y2) {
  54.             return (x1 * y2) - (y1 * x2);
  55.         }
  56.  
  57.         private async void Button_Clicked(object sender, EventArgs e)
  58.         {
  59.             await Navigation.PopModalAsync();
  60.         }
  61.     }
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment