#!/bin/bash # Number of rows for the pattern rows=3 # Function to calculate binomial coefficient binomial_coefficient() { n=$1 k=$2 res=1 for (( i=0; i<k; i++ )); do res=$((res * (n - i) / (i + 1))) done echo $res } # Generate Pascal's Triangle for (( i=0; i<rows; i++ )); do for (( j=0; j<=i; j++ )); do # Print binomial coefficient echo -n "$(binomial_coefficient $i $j) " done echo "" # Move to the next line done
#!/bin/bash # Correct array initialization arr=("apple" "banana" "cherry" "date") # Print array elements echo "Array elements:" for element in "${arr[@]}"; do echo "$element" done
#!/bin/bash # Number of rows for the pattern rows=4 # Loop through each row for ((i=0; i<rows; i++)); do # Print numbers from 0 to i for ((j=0; j<=i; j++)); do echo -n "$j " done # Move to the next line after each row echo done
Comments
Post a Comment