个人Blog: hhktony.com
全部博文(553)
分类: LINUX
2011-12-03 09:47:06
#include
#include
int main(int argc, char **argv)
{
int m, n, i;
long sum = 0;
if(argc != 3)
{
printf("\n Usage:sumint m n\n");
return;
}
m = atoi(argv[1]);
n = atoi(argv[2]);
if((m <= 0) || (m >= n) || (n >= 32000))
{
printf("\n Input error.(0 < m < n < 32000)\n");
return;
}
for(i = m; i <= n; i++)
{
sum = sum + i;
}
printf("The sum: %d\n", sum);
return 0;
}
该程序编译后运行的命令如下:
sumint m n
例如 sumint 15 312
argc = 3;
argv如下:
argv[0] = "sumint"
argv[1] = "15";
argv[2] = "312";