ret_0

c# prac5 var 18

Oct 24th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. // 1
  2. using System;
  3.                    
  4. public class Program
  5. {
  6.    
  7.     static double f(double x1, double y1, double x2, double y2)
  8.     {
  9.         return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  10.     }
  11.    
  12.     static double min(double a, double b)
  13.     {
  14.         return a > b ? b : a;
  15.     }
  16.    
  17.     public static void Main()
  18.     {
  19.         Console.Write("Minimal distance between 3 points\nEnter first point:\nx = ");
  20.         double x1, x2, x3, y1, y2, y3;
  21.         x1 = double.Parse(Console.ReadLine());
  22.         Console.Write("y = ");
  23.         y1 = double.Parse(Console.ReadLine());
  24.         Console.Write("Enter second point:\nx = ");
  25.         x2 = double.Parse(Console.ReadLine());
  26.         Console.Write("y = ");
  27.         y2 = double.Parse(Console.ReadLine());
  28.         Console.Write("Enter third point:\nx = ");
  29.         x3 = double.Parse(Console.ReadLine());
  30.         Console.Write("y = ");
  31.         y3 = double.Parse(Console.ReadLine());
  32.         double d1, d2, d3, d;
  33.         d1 = f(x1, y1, x2, y2);
  34.         d2 = f(x1, y1, x3, y3);
  35.         d3 = f(x3, y3, x2, y2);
  36.         d = min(d1, d2);
  37.         d = min(d, d3);
  38.         Console.Write("\nMinimal distance between ");
  39.         if(d == d1)
  40.             Console.Write("first and second");
  41.         else if(d == d2)
  42.             Console.Write("first and third");
  43.         else
  44.             Console.Write("second and third");
  45.         Console.Write(" point and it is {0:.###}", d);
  46.     }
  47. }
  48.  
  49.  
  50. // 2 & 3
  51. using System;
  52.                    
  53. public class Program
  54. {
  55.    
  56.     static double f(double x)
  57.     {
  58.         double y;
  59.         if(x < 3)
  60.             y = x*x - 0.3;
  61.         else if(x > 5)
  62.             y = x*x + 1;
  63.         else
  64.             y = 0;
  65.         return y;
  66.     }
  67.    
  68.     static double f(double x, out double y)
  69.     {
  70.         if(x < 3)
  71.             y = x*x - 0.3;
  72.         else if(x > 5)
  73.             y = x*x + 1;
  74.         else
  75.             y = 0;
  76.         return 0;
  77.     }
  78.    
  79.     public static void Main()
  80.     {
  81.         Console.Write("table of f(x) where a <= x <= b by step h\nEnter a = ");
  82.         double a, b, h, i;
  83.         a = double.Parse(Console.ReadLine());
  84.         Console.Write("Enter b = ");
  85.         b = double.Parse(Console.ReadLine());
  86.         Console.Write("Enter h = ");
  87.         h = double.Parse(Console.ReadLine());
  88.         Console.Write("Now table:\n");
  89.         for(i = a; i <= b; i += h)
  90.         {
  91.             Console.Write("F({0}) = {1}\n", i, f(i));
  92.         }
  93.         Console.Write("\nTable overloaded:\n");
  94.         for(i = a; i <= b; i += h)
  95.         {
  96.             double y;
  97.             f(i, out y);
  98.             Console.Write("F({0}) = {1}\n", i, y);
  99.         }
  100.     }
  101. }
Add Comment
Please, Sign In to add comment