int main ( ) { unsigned m,n; nod * prim1=NULL, *prim2=NULL, * cat, * rest, * aux; cout<<"Nr termeni primul polinom= "; cin>>m; creare ( prim1, m ); afiseaza ( prim1 ); cout<<"Nr termeni al doilea polinom= "; cin>>n; creare ( prim2, n ); afiseaza ( prim2 ); cout<<"suma:\n"; aux=adunare ( prim1, prim2 ); afiseaza ( aux ); cout<<"diferenta:\n"; aux=adunare ( prim1, negativ ( prim2 ) ); afiseaza ( aux ); cout<<"produs:\n"; aux=mul ( prim1, prim2 ); afiseaza ( aux ); cout<<"cat:\n"; divp ( prim1, prim2, cat, rest ); afiseaza ( cat ); cout<<"rest:\n"; aux=adunare ( prim1, prim2 ); if ( !rest ) cout<<"0"; else afiseaza ( rest ); getch ( ); return 0; }
nod * mul ( nod * prim1, nod * prim2 ) { nod * prim=NULL; while ( prim2 ) { nod * aux=NULL, * aux1; aux=mulmonom ( prim1, prim2->coeficient, prim2->grad ); aux1=prim; prim=adunare ( prim, aux ); sterg ( aux ); sterg ( aux1 ); prim2=prim2->adr; } return prim; }
void divp ( nod * deim, nod * imp, nod *& cat, nod *& rest ) { float coef; unsigned gradul; cat=rest=NULL; while ( deim ) { adaug1 ( rest, deim->coeficient, deim->grad ); deim=deim->adr; } while ( rest->grad>=imp->grad ) { coef=rest->coeficient/imp->coeficient; gradul=rest->grad-imp->grad; adaug1 ( cat, coef, gradul ); nod * factor=NULL; adaug1 ( factor, coef, gradul ); nod * pol=mul ( imp, factor ); sterg ( factor ); nod * neg=negativ ( pol ); sterg ( pol ); rest=adunare ( rest, neg ); sterg ( neg ); } }
int main ( ) { freopen ( "petrecere.in" , "r", stdin ) ; freopen ( "petrecere.out", "w", stdout ) ; int n , i ; scanf ( "%d" , & n ) ; a[2][0] = 1 ; a[2][1] = 2 ; a[1][0] = a[1][1] = 1 ; for ( i = 3 ; i <= n ; ++ i ) { inmultire ( i-1 , a[(i-2)%3] , a[i%3]) ; adunare ( a[i%3] , a[(i-1)%3] , a[i%3] ) ; } for ( i = a[n%3][0] ; i >= 1 ; -- i ) printf ( "%d" , a[n%3][i] ) ; return 0 ; }