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"
                  else
                  print*,"f(x)=2*x*x+3*x+4"
                  endif




print*,"x=",x
print*,f(x)
end program function_f_x


function f(x)
implicit none
real::f
real,intent(in)::x
if(abs(x)<2.0)then
f=(2.0*x**2)+(3.0*x)+4.0
       elseif(abs(x)==2.0)then
        f=0.0
       else
        f=(2.0*x**2)+(3.0*x)-4.0
       endif
end function f




Popular posts from this blog

Some Funny Mathematical Questions

Puthon3

পৃথিবীর কোনো এক আদিম সকাল