N<- 30 
K<- 5   
n<- 4   
x<- 0:4
pmf<- dhyper(x,m = K,n = N - K,k = n) #pmf of X

cdf<- phyper(x,m = K,n = N - K,k = n) #cdf of X
results<- data.frame(
  x = x,
  pmf = round(pmf, 6),
  cdf = round(cdf, 6)
)

print("Probability Mass Function(pmf) and Cumulative Distribution Function(cdf):")
## [1] "Probability Mass Function(pmf) and Cumulative Distribution Function(cdf):"
print(results)
##   x      pmf      cdf
## 1 0 0.461595 0.461595
## 2 1 0.419631 0.881226
## 3 2 0.109469 0.990695
## 4 3 0.009122 0.999818
## 5 4 0.000182 1.000000
plot(stepfun(x, c(0, cdf)), 
     main = "CDF of X (Number of Defective Microwaves)",
     xlab = "Number of Defectives(x)", 
     ylab = "F(x)",
     verticals = FALSE,
     col.points = "blue",
     pch = 16,
     xlim = c(-0.5, 4.5),
     ylim = c(0, 1.1))

points(x, cdf, col = "blue", pch = 16)
grid()
for (i in 1:length(x)) {
  segments(x[i], c(0, cdf)[i], x[i], cdf[i], lty = 2, col = "gray")  #adding dashes for the steps
  if (i < length(x)) {
    segments(x[i], cdf[i], x[i + 1], cdf[i], lty = 2, col = "gray")
  }
}
segments(max(x), 1, max(x) + 1, 1, lty = 2, col = "gray")