Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
class hadeel
{
public static void Main()
{
// polynomial A_n x^n + A_n-1 + .......+ A_1 x + A_0
//the power of polynomial
Console.WriteLine("Enter the highest degree of poly1"); //1
int alength = int.Parse(Console.ReadLine()); //4
// A[] coefficients of first polynomial
int[] A = new int[alength+1]; //6
for (int i = 0; i < A.Length; i++) //8 2n
{
Console.WriteLine("Enter the coeff of x^" + i + ":"); // 8 3n
int b = int.Parse(Console.ReadLine()); // 8 6n
A[i] = b; // 8 7n
}
//the power of polynomial
Console.WriteLine("Enter the highest degree of poly2"); //9 6n
int blength = int.Parse(Console.ReadLine()); //12 6n
// B[] coefficients of second polynomial
int[] B = new int[ blength + 1]; //14 6n
for (int i = 0; i < B.Length; i++) // 15 8n
{
Console.WriteLine("Enter the coeff of x^" + i + ":"); // 15 9n
int b = int.Parse(Console.ReadLine()); // 15 12n
B[i] = b; //15 13n
}
int finallength = (A.Length > B.Length ? A.Length : B.Length);
//set the information to function sum and Write it down
int[] sum = Sum(A, B, A.Length, B.Length, finallength);
Console.WriteLine("sum polynomial is ");
printPolysumsub(sum, finallength);
//set the information to function subtract and Write it down
Console.WriteLine("sub polynomial is ");
int[] sub = SUB(A, B, A.Length, B.Length, finallength);
printPolysumsub(sub, finallength);
//set the information to function multiply and Write it down
Console.WriteLine("mul polynomial is ");
int[] mul =Mul(A, B, A.Length, B.Length, finallength);
printPolymul(mul, finallength);
}
// sum a polynomial
static int[] Sum(int[] A, int[] B, int m, int n , int size)
{
int[] sum = new int[size];
// Initialize polynomial
for (int i = 0; i < m; i++)
{
sum[i] = A[i];
}
// sum every term of polynomial
for (int i = 0; i < n; i++)
{
sum[i] += B[i];
}
return sum;
}
// Subtract the polynomial
static int[] SUB(int[] A, int[] B, int m, int n , int size)
{
int[] sub = new int[size];
// Initialize polynomial
for (int i = 0; i < m; i++)
{
sub[i] = A[i];
}
//sub ever term of polynomial
for (int i = 0; i < n; i++)
{
sub[i] -= B[i];
}
return sub;
}
// multiply the polynomial
static int[] Mul(int[] A, int[] B, int m, int n , int size)
{
int[] mul = new int[size];
// Initialize polynomial
for (int i = 0; i < m; i++)
{
mul[i] = A[i];
}
// mul ever term of first polynomial
for (int i = 0; i < n; i++)
{
mul[i] *= B[i];
}
return mul;
}
// print a polynomial
static void printPolysumsub(int[] poly, int n)
{
for (int i = 0; i < n; i++)
{
Console.Write(poly[i]); //write the first number without x
if (i != 0)
{
Console.Write("x^" + i); //write the powr of x
}
if (i != n - 1)
{
Console.Write(" + ");
}
}
Console.WriteLine(" ");
}
// print a polynomial
static void printPolymul(int[] poly, int n)
{
for (int i = 0; i < n; i++)
{
Console.Write(poly[i]); //write the first number without x
if (i == n-1) //write the powr of final x
{
Console.Write("x^" + i);break;
}
if (i != 0)
{
Console.Write("x^" +(i+ i)); //write the powr of x
}
if (i != n - 1)
{
Console.Write(" + ");
}
}
Console.WriteLine(" ");
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team