Chinaunix首页 | 论坛 | 博客
  • 博客访问: 424367
  • 博文数量: 158
  • 博客积分: 1855
  • 博客等级: 上尉
  • 技术积分: 1888
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-18 14:19
文章分类

全部博文(158)

文章存档

2013年(4)

2012年(16)

2011年(10)

2010年(40)

2009年(61)

2008年(33)

分类: LINUX

2008-12-24 10:05:24

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]#
阅读(1056) | 评论(0) | 转发(0) |
0

上一篇:declare

下一篇:配置网络的四种方法

给主人留下些什么吧!~~