Advertisement
filin

laba_5_z_2_mk1

Sep 26th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 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. namespace Z_2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int q = 1;
  14.             while (q == 1)
  15.             {
  16.                 Console.Write("введите начало диапазона. a= ");
  17.                 double a = double.Parse(Console.ReadLine());
  18.                 Console.Write("введите конец диапазона. b= ");
  19.                 double b = double.Parse(Console.ReadLine());
  20.                 Console.Write("введите размер шага. h= ");
  21.                 double h = double.Parse(Console.ReadLine());
  22.                 double z;
  23.                 for (double i = a; i <= b; i = i + h)
  24.                 {
  25.                     Console.WriteLine("При x ={0}, y ={1}", i, f(i));
  26.  
  27.                     if (i != b)
  28.                     {
  29.                         i+=h;
  30.                        
  31.                         Console.WriteLine("При x ={0}, y ={1}", i, f(i,out z));
  32.                     }
  33.                 }
  34.                 Console.Write("если хотите продолжить введите 1 :  ");
  35.                 q = int.Parse(Console.ReadLine());
  36.             }
  37.  
  38.         }
  39.         static double f(double x)
  40.         {
  41.             if (x < 0)
  42.             {
  43.                 return -4;
  44.             }
  45.             else
  46.             {
  47.                 if (x < 1)
  48.                 {
  49.                     double y = Math.Pow(x, 2) + 3 * x + 4;
  50.                     return y;
  51.                 }
  52.                 else
  53.                 {
  54.                     return 2;
  55.                 }
  56.             }
  57.         }
  58.         static void f(double x, out double y)
  59.  
  60.         {
  61.             if (x < 0)
  62.             {
  63.                 y = -4;
  64.             }
  65.             else
  66.             {
  67.                 if (x < 1)
  68.                 {
  69.                     y = Math.Pow(x, 2) + 3 * x + 4;
  70.                 }
  71.                 else
  72.                 {
  73.                     y = 2;
  74.                 }
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement