forked from kalmar/DALGLI0
68 lines
1.2 KiB
Plaintext
68 lines
1.2 KiB
Plaintext
|
#include<iostream>
|
||
|
#include <conio.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
|
||
|
int *iloczyn(int A[], int B[], int m, int n)
|
||
|
{
|
||
|
int *w = new int[m+n-1];
|
||
|
for (int i = 0; i<m+n-1; i++)
|
||
|
w[i] = 0;
|
||
|
for (int i=0; i<m; i++)
|
||
|
{
|
||
|
for (int j=0; j<n; j++)
|
||
|
w[i+j] += A[i]*B[j];
|
||
|
}
|
||
|
|
||
|
return w;
|
||
|
}
|
||
|
|
||
|
void Wypisz(int wielomian[], int n, int modulo)
|
||
|
{
|
||
|
for (int i=0; i<n; i++)
|
||
|
{
|
||
|
cout << wielomian[i]%modulo;
|
||
|
if (i != 0)
|
||
|
cout << "x^" << i ;
|
||
|
if (i != n-1)
|
||
|
cout << " + ";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
do {
|
||
|
int x;
|
||
|
cout << "Podaj n: ";
|
||
|
cin>>x;
|
||
|
int a,b;
|
||
|
cout <<"Podaj stopien wielomianu 1: ";
|
||
|
cin >> a;
|
||
|
cout <<"Podaj stopien wielomianu 2: ";
|
||
|
cin >> b;
|
||
|
int A[a];
|
||
|
int B[b];
|
||
|
for (int i=0;i<a+1;i++){
|
||
|
|
||
|
cout<<"Podaj kolejne wartosci wielomianu 1: ";
|
||
|
cin >> A[i];
|
||
|
|
||
|
}
|
||
|
for (int j=0;j<b+1;j++){
|
||
|
|
||
|
cout<<"Podaj kolejne wartosci wielomianu 2: ";
|
||
|
cin >> B[j];
|
||
|
|
||
|
}
|
||
|
int *przyklad = iloczyn(A, B, a+1, b+1);
|
||
|
cout << "Wynik: " ;
|
||
|
Wypisz(przyklad, a+b+1, x);
|
||
|
cout <<endl;
|
||
|
cout << "Aby zakonczyc wcisnij ESC" << endl;
|
||
|
cout << "Aby policzyc ponownie wybierz dowolny inny klawisz" << endl << endl;
|
||
|
}
|
||
|
while (getch() != 27);
|
||
|
return 0;
|
||
|
}
|