Main function
calculate_binomial_and_poisson <- function() { n <- as.integer(readline(“Enter value of n:”)) if (is.na(n) || n <= 0) { cat(“Error: ‘n’ must be a positive integer.”) return() }
p <- as.numeric(readline(“Enter value of p:”)) if (is.na(p) || p < 0 || p > 1) { cat(“Error: ‘p’ must be a number between 0 and 1.”) return() }
k <- as.integer(readline(“Enter value of k:”)) if (is.na(k) || k < 0 || k > n) { cat(“Error: ‘k’ must be a non-negative integer less than or equal to ‘n’.”) return() }
binomial <- binomial_coefficient(n, k) poisson <- poisson_approximation(n, p, k)
cat(“Exact value of b(n; p; k):”, binomial, “”) cat(“Poisson approximation:”, poisson, “”) }