Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE FROM PROBLEM 4 Program Binomial IMPLICIT NONE INTEGER :: n INTEGER :: i PRINT *, 'Please enter for value for n' READ *, n

image text in transcribed

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 halted

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

Write the properties of Group theory.

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago