Find the output of the following program if when the user run the program enters the number 6. I.e. after the statement: "Enter a positive integer k", the user enters 6.

            program FUNCTION1

 

            implicit none

 

            INTEGER :: n, MySum, MyFact

 

            PRINT *, "Enter a positive integer k"

 

            READ *, n

 

            MySum=Add(n)

 

            MyFact=Fact(n)

 

            PRINT *, "sum= ", MySum

 

            PRINT *, "Factorial= ", MyFact

 

            !PRINT *, "n= ", n

 

            CONTAINS

 

                        FUNCTION Add(k)

 

                                    INTEGER :: i, Add

           

                                    INTEGER, INTENT(IN) :: k

 

                                    Add=0

 

                                    DO i=1, k

 

                                                Add=Add+i

 

                                    END DO

                       

                        END FUNCTION Add

 

                        FUNCTION Fact(k)

 

                                    INTEGER :: i, Fact

 

                                    INTEGER, INTENT(IN) :: k

 

                                    Fact=1

 

                                    DO i=1, k

 

                                                Fact=Fact*i

 

                                    END DO

                       

                        END FUNCTION Fact

 

 

            end program FUNCTION1

 


Iyad Abu-Jeib's Homepage