Hello all! I’m trying to print fibonacci series with negative numbers. Here is the code:
class fibonacci_series;
real term_fib_1;
real term_fib_2;
int terms_total_fib;
real term_fib_sum;
int i;
function void terms_needed(real term_fib_1 = -3 , real term_fib_2 = -8 , int terms_total_fib = 10);
$display("\nTerms are term_fib_1 = %0d and term_fib_2 = %0d",term_fib_1,term_fib_2);
$display("\nThe number of terms needed in the fibonacci series are %0d", terms_total_fib);
endfunction: terms_needed
task operation_fibonacci(real term_fib_1 = -3, real term_fib_2 = -8 , terms_total_fib = 10);
for(i=1;i<=terms_total_fib;i++)
begin
term_fib_sum = term_fib_1 + term_fib_2;
term_fib_1 = term_fib_2;
term_fib_2 = term_fib_sum;
$display("\n%0d",term_fib_sum);
end
endtask: operation_fibonacci
endclass: fibonacci_series
module fibonacci_series_using_class;
fibonacci_series f;
initial begin
f = new();
f.terms_needed;
f.operation_fibonacci;
end
endmodule
O/P I got:
Terms are term_fib_1 = 4294967293 and term_fib_2 = 4294967288
#
# The number of terms needed in the fibonacci series are 10
#
# The required Fibonacci Series with 0 terms is
#
# 4294967285
#
# 4294967277
#
# 4294967266
#
# 4294967247
#
# 4294967217
#
# 4294967168
#
# 4294967089
#
# 4294966961
#
# 4294966754
#
# 4294966419
How do I rectify this? Thank you in advance.