shell程序如下:
[root@qq shell]# cat for.sh
#!/bin/bash
#for.sh
declare -i s
for((i=0;i<=100;i++))
do
s=s+i
done
echo "the count is $s"
[root@qq shell]# bash for.sh
the count is 5050
[root@qq shell]# cat f.sh
#!/bin/bash
#f.sh
sum=0;i=1
while [ $i -le 100 ]
do
sum=$(($sum+$i))
i=`expr $i + 1`
done
echo "the sum is $sum"
[root@qq shell]# bash f.sh
the sum is 5050
[root@qq shell]# cat f.c
main()
{
int sum=0,i;
for(i=1;i<=100;i++)
sum=sum+i;
printf("the sum is %d\n",sum);
}
[root@qq shell]# gcc -o f f.c
[root@qq shell]# f
the sum is 5050
[root@qq shell]#
[root@qq shell]#
阅读(1092) | 评论(0) | 转发(0) |