奇数
#!/bin/bash
echo " ( 1..100 )内的奇数:"
for i in {1..100};do
A=$(expr $i % 2)
if [ $A -ne 0 ];then
echo $i
fi
done
偶数
#!/bin/bash
echo " (1-100) 内的偶数:"
for i in {1..100};do
A=$(expr $i % 2)
if [ $A -eq 0 ]
then
echo $i
fi
done
质数
#!/bin/bash
echo " 显示{1.100}质数:"
for i in {1..100};do
A=$(factor $i |awk ‘{print NF}‘)
if [ $A -eq 1 ] || [ $A -eq 2 ];then
echo "$i是质数"
fi
done
合数
#!/bin/bash
for i in {1..100};do
A=$(factor $i |awk ‘{print NF}‘)
if [ $A -ne 1 ] && [ $A -ne 2 ];then
echo "$i是合数"
fi
done
~
原文地址:https://www.cnblogs.com/zc1741845455/p/10888790.html
时间: 2024-11-05 15:53:41