এখন আমরা শিখব কিভাবে If statement এর সাহায্যে Fortran এ
একটি problem solve করা যায়।
What
is if statement ?
If statement এ্কটি
conditional
statement যা একটি statement বা একটি arithmetic expression সত্য
আথবা অসত্য নির্দেষ করে।
সাধারণত তিন ধরণের if statement পাওয়া যায়।
1.
logical if statement
2.
Block if statement
3.
Arithmetic if statement
How
to solve a problem in Force2.0
Find
the sum of the series by using if statement
Y=1+2+3+………….+N
Solution
1234567890
Print*, ‘enter the value of n’
Read*, n
K=1
Sum = 0.0
10
sum =sum + k
k=k+1
if (k .le. n)
go to 10
print*, ‘the value of the result is ‘
print*, sum
End
It’s
works like as do statement . Here we use the
if statement if(k.le.n) means that , if k less then equal n then go to 10 , 10 is the statement level . And
the statement (sum =sum+k) is defined as the level 10. The procedure will
continue until k is less then equal n .i.e k=1,2,3,4…………..<= n. if k is >
n then the process will be brought to path of end.
**Let’s
do another problem
Given
that
Values
of x
|
Result
|
5.65
|
The
value of x is less then 10
|
8.45
|
The
value of x is less then 10
|
12.7
|
The
value of Y is = 17.9005585
|
21.65
|
The
value of Y is = 48.869709
|
15.7
|
The
value of Y is = 26.5071354
|
Given
the formula
Then calculate Y if x greater then 10 and if x is less then 10 then print ‘ the
value of x is less then 10’
Solution
1234567890
Do N = 1,5
Write(*,*) ‘Enter the value of
x’
Read(*,*) x
If( x .gt. 10) then
Y=sqrt(x**0.45)+(x**2/10)
Print*, ‘The value of Y is =
‘, Y
Else
Print*, ‘The value of x is
less then 10’
End if
End do
End
Description:
Here
is use do statement because we have 5 values of x so N = 1, 5 as the program
run 5 times for each values of x. We have to remind that do statement must be
stop by the statement End do and If statement must be stop by End if statement.
If
you try more you can learn more.

No comments:
Post a Comment