** Find odd numbers between 1
to 100 by using both Do and If statement.
Solution
1234567890
Write(*,*) ‘Enter the value of
n’
Read(*,*) n
Do 10 k = 1,n ,2
Write(*,*) ‘ the value of odd number ‘ , k
10
Continue
End
Description
Here we put n=100 and I use
Do 10 k (here 10 is statement level) and continue is the placed at the
statement End do. This is another way to write End do statement.
Here I also use k=1,n,2 .
Here increment is 2 that means k takes values 1,3,5,7………..,99 here we see
increment is 2.
**Now by using if statement
we have to find out the odd numbers
1234567890
Write(*,*) ‘enter the value of n’
Read(*,*)n
Y=1
20
Write(*,*) ‘the value of the odd number ‘ , Y
Y=Y+2
If ( Y .lt. n) go to 20
End
Here we put n = 100. Because
we have to show the odd numbers between
1 to 100.
** Find all even number
between 0 to 100 by using if statement.
1234567890
write(*,*) 'Enter the value of N'
read(*,*) N
Y = 0
10 write(*,*) 'The value of the even number' , Y
Y= Y+ 2
If (Y .lt. n) go to 10
End
** Find all even number
between 1 to 100 by using do statement
1234567890
write(*,*) 'Enter the value of N'
read(*,*) N
Do i = 0, N
write(*,*) 'The value of even number is '
, i
End do
End
Here we put N = 100.
No comments:
Post a Comment