Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function real paragontiko(input int m);
  2.         real total;
  3.         total = 1;
  4.         for (int i = 1; i <= m; i++) begin
  5.             total = total * i;
  6.         end
  7.         return total;
  8.     endfunction
  9.  
  10.     initial begin
  11.         int  N=-5;
  12.         real sum, total_sum;
  13.  
  14.        
  15.  
  16.         if(N<=0) begin
  17.             $display("Error, N should be >0",);
  18.             $finish;
  19.         end
  20.  
  21.         sum=0.0;
  22.         total_sum = 0.0;
  23.         for (int i=1; i<=N; i++) begin
  24.             if(i%2==0) begin
  25.                 sum = 1.0/real'(i) - 1.0/paragontiko(i);
  26.             end else begin
  27.                 sum = 1.0/real'(i) + 1.0/paragontiko(i);
  28.             end
  29.             $display("sum=%f",sum);
  30.             total_sum = total_sum + sum;
  31.         end
  32.  
  33.         $display("S=%f",total_sum);
  34.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement