Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
PROGRAM part1a IMPLICIT NONE INTEGER::number, result, answer, FACT2 WRITE(*,'(A)',ADVANCE = "NO")"Enter the number which you want to calculate the factorial:" READ(*,*) number IF(number<0)THEN WRITE(*,*)"You did not enter a positive number." STOP END IF WRITE(*,*)"Using recursive funtions:" WRITE(*,*)FACT2(number) WRITE(*,*)"Using recursive subroutine:" CALL FACT1(number,result) WRITE(*,*)result END PROGRAM !Recursive funtion RECURSIVE INTEGER FUNCTION FACT2(number) RESULT(answer)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: IMPLICIT NONE INTEGER, INTENT(IN)::number IF (number==0)THEN answer=1 ELSE answer=number * FACT2(number-1) END IF END FUNCTION FACT2 !subroutine RECURSIVE SUBROUTINE FACT1(number, result) IMPLICIT NONE INTEGER,INTENT(IN)::number INTEGER, INTENT(OUT)::result INTEGER::temp IF(number==0)THEN result=1 ELSE CALL FACT1(number-1, temp) result=number*temp END IF END SUBROUTINE FACT1...
View Full Document

This note was uploaded on 07/22/2010 for the course MAE 112 taught by Professor Freeh during the Spring '10 term at North Country Community College.

Ask a homework question - tutors are online