Data Structures in C
Machinery Industry Press
Ellis horrowitz, Sartaj Sahni, by Susan Anderson-freed
Translated by Li Jianzhong, Zhang Yan, and Li Zhijun
1.2.2 Calculation of polynomials Based on the Horna rule
1.2.10 Recursive Implementation of the Ackerman Function
1.2.11 Recursive Implementation of the tower
# Include <stdio. h> # Define max 20 Int main () { Float a [Max]; Float x0; Float sum; Int N; Printf ("Enter the maximum number of polynomials you want to calculate n \ n "); Scanf ("% d", & N ); Printf ("Enter the value from A0 to an: \ n "); For (INT I = 0; I <n + 1; I ++) { Scanf ("% F", & A [I]); } Printf ("Enter the value of x0 \ n "); Scanf ("% F", & X0 ); Sum = A [n] * x0 + A [n-1]; N --; While (n! = 0) { Sum = sum * x0 + A [n-1]; N --; } Printf ("sum of polynomials % F \ n", sum ); Return 0; } |
# Include <stdio. h> Void hannuota (INT, Char, Char, char ); Void mov (char, char ); Void main () { Int N; Printf ("Enter the initial number of disks on A: \ n "); Scanf ("% d", & N ); Hannuota (n, 'A', 'B', 'C '); } Void hannuota (int n, char a, char B, char C) { If (n = 1) mov (a, c ); Else { Hannuota (n-1, 'A', 'C', 'B '); MoV (a, c ); Hannuota (n-1, 'B', 'A', 'C '); } } Void mov (char P, char q) { Printf ("Move: % C --> % C \ n", p, q ); } |