Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ForZakaz2
- {
- class Mnog
- {
- public int[] Koof { get; set; }
- public Mnog(int MaxIndex)
- {
- int[] Koof = new int[MaxIndex+1];
- for (int i = 0; i < MaxIndex+1; i++)
- {
- Console.WriteLine("Введите коофициент при x^" + (MaxIndex-i));
- Koof[i] = int.Parse(Console.ReadLine());
- }
- this.Koof = Koof;
- }
- public void Print()
- {
- for (int i = 0; i < this.Koof.Length; i++)
- {
- Console.Write(this.Koof[i] + "x^" + (this.Koof.Length-1-i));
- if(i<(this.Koof.Length-1)){ Console.Write(" + "); }
- }
- Console.WriteLine("");
- }
- public void Int(int x)
- {
- int sum = 0;
- for (int i = 0; i < Koof.Length; i++)
- {
- sum += this.Koof[i] * Recurs(x, this.Koof.Length-1-i);
- }
- Console.WriteLine("P(" + x + ") = " + sum);
- }
- private int Recurs(int x, int n)
- {
- int x2=1;
- while (n > 0)
- {
- x2 *= x;
- n--;
- }
- return x2;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("");
- Console.WriteLine("Задача 2");
- Console.WriteLine("");
- Console.WriteLine("Введите наивысшую степень многочлена P1");
- int n = int.Parse(Console.ReadLine());
- Mnog P1 = new Mnog(n);
- Console.WriteLine("Введите наивысшую степень многочлена P2");
- n = int.Parse(Console.ReadLine());
- Mnog P2 = new Mnog(n);
- P1.Print();
- P2.Print();
- n = int.Parse(Console.ReadLine());
- P1.Int(n);
- n = int.Parse(Console.ReadLine());
- P2.Int(n);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment