Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1
- using System;
- public class Program
- {
- static double f(double x1, double y1, double x2, double y2)
- {
- return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- }
- static double min(double a, double b)
- {
- return a > b ? b : a;
- }
- public static void Main()
- {
- Console.Write("Minimal distance between 3 points\nEnter first point:\nx = ");
- double x1, x2, x3, y1, y2, y3;
- x1 = double.Parse(Console.ReadLine());
- Console.Write("y = ");
- y1 = double.Parse(Console.ReadLine());
- Console.Write("Enter second point:\nx = ");
- x2 = double.Parse(Console.ReadLine());
- Console.Write("y = ");
- y2 = double.Parse(Console.ReadLine());
- Console.Write("Enter third point:\nx = ");
- x3 = double.Parse(Console.ReadLine());
- Console.Write("y = ");
- y3 = double.Parse(Console.ReadLine());
- double d1, d2, d3, d;
- d1 = f(x1, y1, x2, y2);
- d2 = f(x1, y1, x3, y3);
- d3 = f(x3, y3, x2, y2);
- d = min(d1, d2);
- d = min(d, d3);
- Console.Write("\nMinimal distance between ");
- if(d == d1)
- Console.Write("first and second");
- else if(d == d2)
- Console.Write("first and third");
- else
- Console.Write("second and third");
- Console.Write(" point and it is {0:.###}", d);
- }
- }
- // 2 & 3
- using System;
- public class Program
- {
- static double f(double x)
- {
- double y;
- if(x < 3)
- y = x*x - 0.3;
- else if(x > 5)
- y = x*x + 1;
- else
- y = 0;
- return y;
- }
- static double f(double x, out double y)
- {
- if(x < 3)
- y = x*x - 0.3;
- else if(x > 5)
- y = x*x + 1;
- else
- y = 0;
- return 0;
- }
- public static void Main()
- {
- Console.Write("table of f(x) where a <= x <= b by step h\nEnter a = ");
- double a, b, h, i;
- a = double.Parse(Console.ReadLine());
- Console.Write("Enter b = ");
- b = double.Parse(Console.ReadLine());
- Console.Write("Enter h = ");
- h = double.Parse(Console.ReadLine());
- Console.Write("Now table:\n");
- for(i = a; i <= b; i += h)
- {
- Console.Write("F({0}) = {1}\n", i, f(i));
- }
- Console.Write("\nTable overloaded:\n");
- for(i = a; i <= b; i += h)
- {
- double y;
- f(i, out y);
- Console.Write("F({0}) = {1}\n", i, y);
- }
- }
- }
Add Comment
Please, Sign In to add comment