\documentclass{article} \begin{document} \begin{verbatim} 4. Program for Counting the number of occurences of a character in a string program CountC implicit none INTEGER::CountChar character(len = 30):: a character:: ch; write(*,*) "ENTER THE INPUT STRING" read(*,*) a; write(*,*) "ENTER THE CHARACTER TO LOOK FOR" read(*,*) ch print *, CountChar(a, 30, ch) end program INTEGER FUNCTION CountChar(b, size,c ) INTEGER, INTENT(IN)::size CHARACTER(len =size)::b character, INTENT(IN)::c INTEGER :: L, i CountChar = 0; L = len(trim(b)); do i = 1, L if ( b(i:i)==c) then CountChar = CountChar + 1; endif end do end function CountChar 5. Program for finding the factorial of a number Program MyFactorial implicit none integer:: factorial integer:: n Write(*,*)"Enter A positive number" read(*,*) n if (n<0) then print *,"Factorial is not defined for negative numbers" else print *, "The factorial of", n, " is ", factorial(n) endif end Program MyFactorial Recursive function factorial(N) result(ans) implicit none integer:: N integer:: ans if (N==0) then ans = 1; else ans = N * factorial(N-1) endif end function factorial 6.program for finding the nth fibonacci number PROGRAM fibonacci IMPLICIT NONE INTEGER::n, RFIB, IFIB WRITE(*,*) "Please enter the Number:" READ *, n; WRITE(*,*) n,"th Fibonacci number is:", RFIB(n); WRITE(*,*) n,"th Fibonacci number is:", IFIB(n); END PROGRAM INTEGER FUNCTION IFIB(n) !This is the iterative version of the fib series. INTEGER, INTENT(IN):: n INTEGER::f0, f1 INTEGER:: i f0 = 0; f1 = 1; DO i = 2, n IFIB = f0 + f1; f0 = f1; f1 = IFIB; END DO RETURN END FUNCTION IFIB RECURSIVE FUNCTION RFIB(n) RESULT(ans) IMPLICIT NONE INTEGER::n, ans IF (n==0) THEN ans = 0; ELSE IF (n==1) THEN ans = 1; ELSE ans = RFIB(n-1)+ RFIB(n-2); ENDIF END FUNCTION RFIB 7. This is the program to find GCD of two numbers PROGRAM GCD IMPLICIT NONE INTEGER:: IGCD, RGCD INTEGER:: num1, num2, tmp WRITE(*,*) "ENTER THE TWO NUMBERS" READ*, num1 READ*, num2 WRITE(*,*) "GCD OF", num1, num2, "IS:", RGCD(num1, num2) END PROGRAM !Iterative method for finf=ding GCD INTEGER FUNCTION IGCD(num1, num2) IMPLICIT NONE INTEGER, INTENT(IN):: num1, num2 INTEGER:: tmp, n1, n2 n1 = num1; n2 = num2; DO IF(n1==0) THEN IGCD = n2; EXIT ELSE IF(n2