bash 스크립트 (숫자의 배수 출력 하기)

2024. 2. 19. 18:20Linux/Bash

728x90
SMALL
  • 개요
Bash script를 사용해서 1에서 100까지 숫자중에 3, 5, 7의 배수를 출력하는 예제이다.

 

  • 예제 1
#!/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

 

  • 예제 2
#!/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
728x90
LIST

'Linux > Bash' 카테고리의 다른 글

bash에서 파일 안에 column 값을 다 더하기  (0) 2023.08.30
rm할 때 물어보기  (1) 2023.03.09
bash history 제한 없애기 (ChatGPT)  (1) 2023.01.31