Posts

Fibonacci number

Image

a function f(x).....in fortran

!Write a function for the function f(x) defiend as followos !f(x)=2*x*x+3*x+4      for  x<2 !f(x)=0                for  x=2 !f(x)=2*x*x+3*x-4      for  x>2 program function_f_x implicit none interface function f(x) real ::f real,intent(in)::x end function f end interface real::x print*,"Please entre value of x" read*,x                   if(x==2)then                   print*,"f(x)=0"                   elseif(x>2)then                   print*,"f(x)=2*x*x+3*x-4"        ...

A function in fortran.

Image
!Illustrate use of function sub program !function sub program is given below program func_use implicit none interface function S(x) real::S real,intent(in)::x end function end interface real::x,g print*,"Please entre the value of x" read*,x print*,"x=",x g=S(x+2)+S(x**2) print*,"g=",g end program func_use function S(x) implicit none real::S real,intent(in)::x S=x**2+x+4 end function

Fortran function example(interest calculation)

Image
   program interest_calculation!This program finding interest by the formula I=P*R*T/100                                implicit none                                                        interface                                                         function interest(bal,intr_rate,time) ...
!Tabulate the function !f(x,y)=(x**2+y**2+2*x*y)/(x**2+y**2+8*x*y) !for the following set of values of (x,y) !(x,y)=(0,-10);(2,-8);(4,-6);(6,-4);(8,-2);(10,0) and  (12,2). program  two_diomonsional_function_tabulation implicit none real ::f_x,x,y integer ::i print*,"      x","  ","              y","  ","               f(x)" do i=0,12,2 x=i y=i-10 f_x=(x**2+y**2+2*x*y)/(x**2+y**2+8*x*y) print*,x,y,f_x enddo end program two_diomonsional_function_tabulation
!write a program to evaluate the following sum: !S=summetion(-1)**n*(x)**(n/2)/(n*(n+1)) for n=1 to 10 program sum_of_a_series implicit none real::x,s_x integer::n print*,"Type value of x" read*,x print*,"x=",x s_x=-.5*sqrt(x) do n=2,10,1 s_x=s_x+s_x*(-1)**n*x**(.5*n+.5)/(n*(n+2)) enddo print*,"S=",s_x end program sum_of_a_series
!given an integer, write aprogram to reverse and print it. program reverse_integer implicit none integer::n,digit,reverse_number reverse_number=0 print*,"type the number" read*,n print*,"      number=",n do if(n==0)then exit else digit=mod(n,10) reverse_number=(digit+reverse_number)*10 n=n/10 endif enddo reverse_number=reverse_number/10 print*,"reverse_number=",reverse_number end program reverse_integer