ChameL1oN

untitled

Mar 23rd, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 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 ForZakaz2
  8. {
  9.     class Mnog
  10.     {
  11.         public int[] Koof { get; set; }
  12.         public Mnog(int MaxIndex)
  13.         {
  14.             int[] Koof = new int[MaxIndex+1];
  15.             for (int i = 0; i < MaxIndex+1; i++)
  16.             {
  17.                 Console.WriteLine("Введите коофициент при x^" + (MaxIndex-i));
  18.                 Koof[i] = int.Parse(Console.ReadLine());    
  19.             }          
  20.             this.Koof = Koof;
  21.         }
  22.         public void Print()
  23.         {
  24.             for (int i = 0; i < this.Koof.Length; i++)
  25.             {
  26.                 Console.Write(this.Koof[i] + "x^" + (this.Koof.Length-1-i));
  27.                     if(i<(this.Koof.Length-1)){ Console.Write(" + "); }
  28.             }
  29.             Console.WriteLine("");
  30.         }
  31.         public void Int(int x)
  32.         {
  33.             int sum = 0;
  34.             for (int i = 0; i < Koof.Length; i++)
  35.             {
  36.                 sum += this.Koof[i] * Recurs(x, this.Koof.Length-1-i);
  37.             }
  38.             Console.WriteLine("P(" + x + ") = " + sum);
  39.         }
  40.         private int Recurs(int x, int n)
  41.         {
  42.             int x2=1;
  43.             while (n > 0)
  44.             {
  45.                 x2 *= x;
  46.                 n--;
  47.             }
  48.             return x2;
  49.         }
  50.     }
  51.  
  52.  
  53.     class Program
  54.     {
  55.         static void Main(string[] args)
  56.         {
  57.  
  58.             Console.WriteLine("");
  59.             Console.WriteLine("Задача 2");
  60.             Console.WriteLine("");
  61.             Console.WriteLine("Введите наивысшую степень многочлена P1");
  62.             int n = int.Parse(Console.ReadLine());
  63.             Mnog P1 = new Mnog(n);
  64.             Console.WriteLine("Введите наивысшую степень многочлена P2");
  65.             n = int.Parse(Console.ReadLine());
  66.             Mnog P2 = new Mnog(n);
  67.             P1.Print();
  68.             P2.Print();
  69.             n = int.Parse(Console.ReadLine());
  70.             P1.Int(n);
  71.             n = int.Parse(Console.ReadLine());
  72.             P2.Int(n);
  73.         }
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment