Question
CODE FROM PROBLEM 4 Program Binomial IMPLICIT NONE INTEGER :: n INTEGER :: i PRINT *, 'Please enter for value for n' READ *, n
CODE FROM PROBLEM 4
Program Binomial IMPLICIT NONE INTEGER :: n INTEGER :: i PRINT *, 'Please enter for value for n' READ *, n PRINT *,'Binomial coefficient:' PRINT *, ' k n!/(k!(n-k)!)' PRINT *, '===================' DO i = 0, n WRITE(*,"(I3,3X,I7)") i, binomial_coefficient(n, i) END DO contains
function binomial_coefficient (n, k) IMPLICIT NONE INTEGER :: binomial_coefficient INTEGER :: n INTEGER :: k binomial_coefficient = factorial(n)/(factorial(k) * factorial(n-k)) END function binomial_coefficient
function factorial(n) IMPLICIT NONE INTEGER :: factorial INTEGER :: n INTEGER :: temp INTEGER :: num temp = 1 DO num = 1, n temp = temp * num END DO factorial = temp
1. Starting with the code that you wrote for Lab Problem 4 to compute binomial coef- ficients, write a Fortran program to ask the user for a value for n and the name of an output file, and call an internal subroutine to write a table of binomial coefficient values to the file. If the user enters 10 for n, the file should contain: Binomial coefficients for n= 10 k n!/(k!(n-k)!) 0 1 2 3 4. 5 6 7 8 9 10 1 10 45 120 210 252 210 120 45 10 1 The subroutine should accept two arguments (for n and the filename) and should call the bicoeff function that you wrote for Lab Problem 4. In the case where the file cannot be opened the user should receive an appropriate message and execution should be halted. 1. Starting with the code that you wrote for Lab Problem 4 to compute binomial coef- ficients, write a Fortran program to ask the user for a value for n and the name of an output file, and call an internal subroutine to write a table of binomial coefficient values to the file. If the user enters 10 for n, the file should contain: Binomial coefficients for n= 10 k n!/(k!(n-k)!) 0 1 2 3 4. 5 6 7 8 9 10 1 10 45 120 210 252 210 120 45 10 1 The subroutine should accept two arguments (for n and the filename) and should call the bicoeff function that you wrote for Lab Problem 4. In the case where the file cannot be opened the user should receive an appropriate message and execution should be haltedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started