Listing multiples of numbers using Bash

bash example

  • outline

Using Bash, make list of multiples of numbers.

  • example 1 (3, 5, 7)

#!/bin/bash
for i in $(seq 1 100); do
    if (( i % 3 == 0 )); then
        echo "Multiple of 3: $i"
    fi
    if (( i % 5 == 0 )); then
        echo "Multiple of 5: $i"
    fi
    if (( i % 7 == 0 )); then
        echo "Multiple of 7: $i"
    fi
done
  • example 2 (3, 5, 7)

#!/bin/bash
for x in 3 5 7; do
for i in $(seq 1 100); do
    if (( i % $x == 0 )); then
        echo "Multiple of $x : $i"
    fi
done
done