wtorek, 31 marca 2020 21:32 Ilona Simek
Drukuj

Horner, Euklides, na dwójkowy

#include <iostream>

using namespace std;
void nadw(int a)
{
if(a!=0)
{
nadw(a/2);
cout<<a%2;
}
}
int eukl(int a, int b)
{
if(a==b) return a;
if(a>b)
return eukl(a-b,b);
else
return eukl(b-a,a);
}

int horner(int x, int tab[],int n)
{
if (n==0) return tab[0];
else
return horner (x,tab,n-1)*x+tab[n];
}
int main()
{
int tab[]={2,3,4,5};
int x,y;
cout<<"podaj liczbe "<<endl;
cin>>x;
cout<<"podaj liczbe "<<endl;
cin>>y;
cout<<x<<" binarnie to ";
nadw(x);
cout<<endl<<"NWD liczb "<<x<<" i "<<y<<" = "<<eukl(x,y)<<endl;

cout<<"wartosc wielomianu dla x = "<<x<<" wynosi "<<horner(x,tab,3)<<endl;
return 0;
}